The following heat map shows how many seconds Math_BigInteger takes to perform encryption / decryption with a 2048-bit RSA key on an Intel Core i5-3320M CPU @ 2.6GHz under various environments. benchmark.phps was used to generate the heatmap. col*.php are all variations of speed.phps.
Math_BigInteger automatically picks the fastest settings to use depending on what extensions it has available at its disposal.
Internal | BCMath | Internal | BCMath | GMP | |
w/o OpenSSL | w/ OpenSSL | ||||
PHP 4.4 | 19.840 | 4.125 | 2.227 | 0.186 | |
PHP 5.0 | 20.338 | 4.099 | 2.353 | 0.193 | |
PHP 5.1 | 8.290 | 4.160 | 1.343 | 0.187 | 0.014 |
PHP 5.2 | 7.944 | 3.995 | 1.210 | 0.177 | 0.014 |
PHP 5.3 | 5.758 | 3.293 | 0.791 | 0.246 | 0.017 |
PHP 5.4 | 3.159 | 5.415 | 0.519 | 0.293 | 0.019 |
PHP 5.5 | 3.719 | 4.459 | 0.485 | 0.227 | 0.020 |
The major limiting factor for the internal implementation is the PHP engine itself. Each successive major version brings with it speed improvements but there's only so much it can do.
GMP, to quote wikipedia, "aims to be faster than any other bignum library", using "highly optimized assembly language code".
Only used for powMod(). Converts the exponent and the modulo to an appropriately formatted RSA public key and performs non-padded RSA encryption with that.