Index: trunk/extensions/InlineScripts/interpreter/benchmark/benchmark.php |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Initial very basic framework for doing some benchmark tests, comparing |
| 6 | + * scripts in the inline script to equivalent raw PHP execution (eval'd) |
| 7 | + * |
| 8 | + * <brion@pobox.com> 2010-04-14 |
| 9 | + */ |
| 10 | + |
| 11 | +if (php_sapi_name() != 'cli') { |
| 12 | + die("cli only"); |
| 13 | +} |
| 14 | + |
| 15 | +require_once "../../../../maintenance/commandLine.inc"; |
| 16 | + |
| 17 | +require_once "../../InlineScripts.php"; // if ext not already enabled |
| 18 | + |
| 19 | +$testcases = array(array( |
| 20 | +'script' => <<<END_SCRIPT |
| 21 | +"Hello, world!"; |
| 22 | +END_SCRIPT |
| 23 | +, |
| 24 | +'php' => <<<END_PHP |
| 25 | +return "Hello, world!"; |
| 26 | +END_PHP |
| 27 | +)); |
| 28 | + |
| 29 | +function runtest( $lang, $source ) { |
| 30 | + if ($lang == 'php') { |
| 31 | + return eval($source); |
| 32 | + } else { |
| 33 | + $scriptParser = new InlineScriptInterpreter(); |
| 34 | + $parser = new Parser(); |
| 35 | + $frame = null; //new Frame(); |
| 36 | + return $scriptParser->evaluate( $source, $parser, $frame ); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +$runs = 10; |
| 41 | +foreach( $testcases as $testcase ) { |
| 42 | + foreach( $testcase as $lang => $code ) { |
| 43 | + $start = microtime( true ); |
| 44 | + $result = runtest( $lang, $code ); |
| 45 | + $delta1 = microtime( true ) - $start; |
| 46 | + for ($i = 1; $i < $runs; $i++) { |
| 47 | + runtest( $lang, $code ); |
| 48 | + } |
| 49 | + $delta = (microtime( true ) - $start) / $runs; |
| 50 | + printf( "%s: %0.3f ms first, %0.3f ms avg of %d runs\n", |
| 51 | + $lang, $delta1 * 1000.0, $delta * 1000.0, $runs ); |
| 52 | + var_dump($result); |
| 53 | + print "\n"; |
| 54 | + } |
| 55 | +} |
Property changes on: trunk/extensions/InlineScripts/interpreter/benchmark/benchmark.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 56 | + native |