Last active
October 20, 2015 14:16
-
-
Save manchicken/5b66401a399c3c71645a to your computer and use it in GitHub Desktop.
Inspired by https://gist.github.com/loganlinn/2165297, I want to see just `strtolower()` in an if though, and I wanted to see the results for larger values of `n`
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
mstemle@mstemle901:~/Desktop$ ./runtests.sh | |
String length: 512 | |
************************ | |
* if + strtolower * | |
************************ | |
Time: 0.001159 | |
Memory: 1904 | |
************************ | |
* strcasecmp * | |
************************ | |
Memory: 1888 | |
Time: 0.000869 | |
String length: 1024 | |
************************ | |
* if + strtolower * | |
************************ | |
Time: 0.004334 | |
Memory: 2928 | |
************************ | |
* strcasecmp * | |
************************ | |
Memory: 2912 | |
Time: 0.001288 | |
String length: 2048 | |
************************ | |
* if + strtolower * | |
************************ | |
Time: 0.012139 | |
Memory: 4976 | |
************************ | |
* strcasecmp * | |
************************ | |
Memory: 4960 | |
Time: 0.003871 | |
String length: 32768 | |
************************ | |
* if + strtolower * | |
************************ | |
Time: 2.708231 | |
Memory: 66416 | |
************************ | |
* strcasecmp * | |
************************ | |
Memory: 66400 | |
Time: 0.384644 |
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
STRTOLOWER="./strtolower_test.php" | |
STRCASECMP="./strcasecmp_test.php" | |
SIZES=( | |
$(expr 1 \* 512) # 1/2 KB | |
$(expr 1 \* 1024) # 1 KB | |
$(expr 1 \* 1024 \* 2) # 2 KB | |
$(expr 1 \* 1024 \* 32) # 32 KB | |
) | |
for i in "${SIZES[@]}"; do | |
echo "String length: $i" | |
$STRTOLOWER "$i" | |
$STRCASECMP "$i" | |
echo -e "\n" | |
done |
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
#!/usr/bin/env php | |
<?php | |
$n = isset($argv[1]) ? (int) $argv[1] : 200; | |
$before = memory_get_usage(); | |
$start = microtime(true); | |
$a = ''; | |
$b = ''; | |
for ($i = 0; $i < $n; $i++) { | |
$a .= $i % 2 ? "A" : 'a'; | |
$b .= 'a'; | |
if ( 0 == strcasecmp($a, $b) ) | |
{ | |
// Do nothing | |
} | |
} | |
$end = microtime(true); | |
$after = memory_get_usage(); | |
printf("************************\n"); | |
printf("* strcasecmp *\n"); | |
printf("************************\n"); | |
printf("Memory: %d\n", $after - $before); | |
printf("Time: %f\n", $end - $start); |
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
#!/usr/bin/env php | |
<?php | |
$n = isset($argv[1]) ? (int) $argv[1] : 200; | |
$before = memory_get_usage(); | |
$start = microtime(true); | |
$a = ''; | |
$b = ''; | |
for ($i = 0; $i < $n; $i++) { | |
$a .= $i % 2 ? "A" : 'a'; | |
$b .= 'a'; | |
if ( strtolower($a) == $b ) { | |
// Do nothing | |
} | |
} | |
$end = microtime(true); | |
$after = memory_get_usage(); | |
printf("************************\n"); | |
printf("* if + strtolower *\n"); | |
printf("************************\n"); | |
printf("Time: %f\n", $end - $start); | |
printf("Memory: %d\n", $after - $before); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment