Created
September 25, 2015 16:14
-
-
Save lucasmichot/a94b4f7a6a5f107945e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
use Base32\Base32; | |
function generateRandomString($length = 10) | |
{ | |
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
$charactersLength = strlen($characters); | |
$randomString = ''; | |
for ($i = 0; $i < $length; $i ++) | |
{ | |
$randomString .= $characters[rand(0, $charactersLength - 1)]; | |
} | |
return $randomString; | |
} | |
function microtime_float() | |
{ | |
list($usec, $sec) = explode(" ", microtime()); | |
return ((float) $usec + (float) $sec); | |
} | |
$items = []; | |
for ($i = 0; $i < 100000; $i ++) | |
{ | |
$items[] = generateRandomString(rand(1, 20)); | |
} | |
$start = microtime_float(); | |
for ($i = 0; $i < 100000; $i ++) | |
{ | |
$e = Base32::encode($items[$i]); | |
$d = Base32::decode($e); | |
} | |
$duration = microtime_float() - $start.PHP_EOL; | |
echo $duration; | |
// master | |
// 8.2193100452423 | |
// 8.3363120555878 | |
// 8.4401090145111 | |
// 8.1804580688477 | |
// 8.5243360996246 | |
// alphabet | |
// 8.4657269668579 | |
// 8.5485459613889 | |
// 8.2104909515381 | |
// 8.5630060100555 | |
// 8.5397568893433 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment