-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two files that do rouglhly the same thing, one written in Primi and one written in PHP. Primi performance is now evaluated "how many times is Primi slower than an equivalent code in PHP?" This should make benchmarks more relevant - and any performance improvements or regressions should be visible better. Currently on my machine: 02.03.2020 22:35, 27.73, perf 37.86x slower vs 0.47678733 ... this is inclusing changes that are not yet commited.
- Loading branch information
Showing
5 changed files
with
156 additions
and
190 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
max_iter = 500000 | ||
|
||
function bench_function_calls() { | ||
|
||
adder = function(x, y) { | ||
return x + y | ||
} | ||
|
||
result = -1024 | ||
c = 0 | ||
while (c < max_iter) { | ||
result = result + adder(c, 1) | ||
c = c + 1 | ||
} | ||
|
||
return c | ||
|
||
} | ||
|
||
function bench_regex_matches() { | ||
|
||
haystack = "Když začínáme myslet, nemáme k dispozici nic jiného než myšlenku v " + | ||
"její čisté neurčenosti, neboť k určení již patří jedno nebo nějaké " + | ||
"jiné, ale na začátku ještě nemáme žádné jiné..." | ||
|
||
result = 0 | ||
c = 0 | ||
while (c < max_iter) { | ||
result = result + (haystack == r"^.*(zač).*(,)?.*?(\.)").to_number() | ||
c = c + 1 | ||
} | ||
|
||
return c | ||
|
||
} | ||
|
||
bench_function_calls() | ||
bench_regex_matches() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
ini_set('display_errors', '1'); | ||
ini_set('display_startup_errors', '1'); | ||
error_reporting(E_ALL); | ||
const MAX_ITER = 500000; | ||
|
||
// | ||
// Run some CPU intensive tasks and measure their duration in pure PHP. | ||
// | ||
|
||
function measure($fn) { | ||
$start = microtime(true); | ||
$fn(); | ||
return microtime(true) - $start; | ||
} | ||
|
||
function bench_function_calls() { | ||
|
||
$adder = function($x, $y) { | ||
return $x + $y; | ||
}; | ||
|
||
$result = -1024; | ||
$c = 0; | ||
while ($c < MAX_ITER) { | ||
$result = $result + $adder($c, 1); | ||
$c = $c + 1; | ||
} | ||
|
||
return $c; | ||
|
||
} | ||
|
||
function bench_regex_matches() { | ||
|
||
$haystack = "Když začínáme myslet, nemáme k dispozici nic jiného než myšlenku v " . | ||
"její čisté neurčenosti, neboť k určení již patří jedno nebo nějaké " . | ||
"jiné, ale na začátku ještě nemáme žádné jiné..."; | ||
|
||
$result = 0; | ||
$c = 0; | ||
while ($c < MAX_ITER) { | ||
$result += preg_match('#^.*(zač).*(,)?.*?(\.)$#', $haystack, $m); | ||
$c = $c + 1; | ||
} | ||
|
||
return $c; | ||
|
||
} | ||
|
||
$results = [ | ||
'bench_function_calls' => measure('bench_function_calls'), | ||
'bench_regex_matches' => measure('bench_regex_matches'), | ||
]; | ||
|
||
// | ||
// Print results in INI format for easy parsing, if needed. | ||
// | ||
|
||
$total = 0; | ||
foreach ($results as $name => $time) { | ||
echo "$name=$time\n"; | ||
$total += $time; | ||
} | ||
echo "total=$total\n"; |