Last active
December 18, 2015 02:29
-
-
Save wangzaixiang/5711409 to your computer and use it in GitHub Desktop.
JavaScript Performance Test
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
<script languange="javascript"> | |
var begin = new Date(); | |
var pie = 0; | |
var loop = 1000 * 1000 * 100; | |
for(var i=1; i<loop; i++){ | |
var sign = (i % 2) == 0 ? -1.0 : 1.0; | |
pie = pie + sign / (2*i - 1) | |
} | |
pie = pie * 4; | |
var end = new Date(); | |
document.write("pie = " + pie + " time = " + (end-begin)); | |
</script> |
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
var begin = new Date(); | |
var pie = 0; | |
var loop = 1000 * 1000 * 100; | |
for(var i=1; i<loop; i++){ | |
var sign = (i % 2) == 0 ? -1.0 : 1.0; | |
pie = pie + sign / (2*i - 1) | |
} | |
pie = pie * 4; | |
var end = new Date(); | |
java.lang.System.out.println("pie = " + pie + " time = " + (end-begin)); |
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 | |
$begin = microtime(true); | |
$pie = 0; | |
$loop = 1000 * 1000 * 100; | |
for($i=1; $i < $loop; $i++){ | |
$sign = ($i % 2) == 0 ? -1.0 : 1.0; | |
$pie = $pie + $sign / (2 * $i - 1); | |
} | |
$pie = $pie * 4; | |
$end = microtime(true); | |
echo "pie = " . $pie . " total time = " . ($end-$begin); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment