Skip to content

Commit

Permalink
build: Fix benchmark unit from seconds to milliseconds
Browse files Browse the repository at this point in the history
microtime returns microsecond-precision floats, in seconds, which
multiplied by 1000 is milliseconds. Correct the unit accordingly.

Also while at it, in avoidance of doubt, report the results based
on observed outcome rather than expected outcome.

Change-Id: I6312b132fed44ab5c98500b3e0ce0173e7ddd6f3
  • Loading branch information
Krinkle committed Jan 22, 2023
1 parent 75ff33d commit b5edf5b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scripts/bench.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

$t = microtime( true );
CommonPasswords::getFilter();
$t = ( microtime( true ) - $t ) * 1000;
echo "Load bloom filter: {$t}s\n";
$t = round( microtime( true ) - $t, 6 ) * 1000;
echo "Load bloom filter: {$t}ms\n";

$passwords = [
'password' => true,
Expand All @@ -20,10 +20,10 @@
foreach ( $passwords as $p => $v ) {
$t = microtime( true );
$isCommon = CommonPasswords::isCommon( $p );
$t = ( microtime( true ) - $t ) * 1000;
if ( $v ) {
echo "Time to check a password that is in the filter: {$t}s\n";
$t = round( microtime( true ) - $t, 6 ) * 1000;
if ( $isCommon ) {
echo "Time to check a password that is in the filter: {$t}ms\n";
} else {
echo "Time to check a password that is not in the filter: {$t}s\n";
echo "Time to check a password that is not in the filter: {$t}ms\n";
}
}

0 comments on commit b5edf5b

Please sign in to comment.