Last active
February 15, 2016 03:57
-
-
Save holyshared/95708dbe21f8ab8cfad4 to your computer and use it in GitHub Desktop.
Benchmark of Hacklang
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
[*.hh] | |
indent_style = space | |
indent_size = 4 | |
[*.md] | |
indent_style = tab | |
indent_size = 2 | |
[*.json] | |
indent_style = space | |
indent_size = 2 |
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
/vendor/ |
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 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
<?hh //strict | |
namespace example; | |
use hhpack\performance as bench; | |
function vector_add_main() : void | |
{ | |
echo "Vector::add", PHP_EOL, PHP_EOL; | |
bench\sync()->times(15)->run(() ==> { | |
$stack = Vector {}; | |
for ($i = 0; $i < 200000; $i++) { | |
$stack->add($i); | |
} | |
}); | |
} | |
function set_add_main() : void | |
{ | |
echo "Set::add", PHP_EOL, PHP_EOL; | |
bench\sync()->times(15)->run(() ==> { | |
$stack = Set {}; | |
for ($i = 0; $i < 200000; $i++) { | |
$stack->add($i); | |
} | |
}); | |
} |
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
<?hh //partial | |
namespace example; | |
require_once __DIR__ . '/vendor/autoload.php'; | |
require_once __DIR__ . '/add.hh'; | |
vector_add_main(); | |
set_add_main(); |
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 bash | |
scripts=(add_main.hh filter_main.hh memoize_main.hh) | |
run_scripts() { | |
for i in "${scripts[@]}" | |
do | |
hhvm -v$1 ${i} | |
done | |
} | |
case "$1" in | |
jiton) | |
run_scripts "Eval.Jit=true" | |
;; | |
jitoff) | |
run_scripts "Eval.Jit=false" | |
;; | |
*) | |
echo $"Usage: $0 {on|off}" | |
RETVAL=1 | |
esac | |
exit $RETVAL |
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
{ | |
"name": "holyshared/bench", | |
"authors": [ | |
{ | |
"name": "Noritaka Horio", | |
"email": "holy.shared.design@gmail.com" | |
} | |
], | |
"require": { | |
"hhvm": ">=3.12.0", | |
"hhpack/performance": "~0.6" | |
}, | |
"minimum-stability": "stable" | |
} |
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
<?hh //strict | |
namespace example; | |
use hhpack\performance as bench; | |
function set_filter_main() : void | |
{ | |
echo "Set::filter", PHP_EOL, PHP_EOL; | |
bench\sync()->times(15)->run(() ==> { | |
$stack = Set {}; | |
for ($i = 0; $i < 200000; $i++) { | |
$stack->add($i); | |
} | |
$stack->filter(($v) ==> $v % 2 === 0); | |
}); | |
} | |
function vector_filter_main() : void | |
{ | |
echo "Vector::filter", PHP_EOL, PHP_EOL; | |
bench\sync()->times(15)->run(() ==> { | |
$stack = Vector {}; | |
for ($i = 0; $i < 200000; $i++) { | |
$stack->add($i); | |
} | |
$stack->filter(($v) ==> $v % 2 === 0); | |
}); | |
} |
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
<?hh //partial | |
namespace example; | |
require_once __DIR__ . '/vendor/autoload.php'; | |
require_once __DIR__ . '/filter.hh'; | |
vector_filter_main(); | |
set_filter_main(); |
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
<?hh //strict | |
namespace example; | |
use hhpack\performance as bench; | |
function memoize_main() : void | |
{ | |
echo "memoize", PHP_EOL, PHP_EOL; | |
$calc = new MemoizeCalculator(); | |
bench\sync()->times(15)->run(() ==> { | |
$calc->calculate(); | |
}); | |
} | |
function non_memoize_main() : void | |
{ | |
echo "non memoize", PHP_EOL, PHP_EOL; | |
$calc = new NonMemoizeCalculator(); | |
bench\sync()->times(15)->run(() ==> { | |
$calc->calculate(); | |
}); | |
} | |
interface Calculator | |
{ | |
public function calculate() : ImmVector<int>; | |
} | |
abstract class ItemsCalculator | |
{ | |
protected function items() : ImmVector<int> | |
{ | |
$stack = Vector {}; | |
for ($i = 0; $i < 200000; $i++) { | |
$stack->add($i); | |
} | |
return $stack->toImmVector(); | |
} | |
} | |
final class MemoizeCalculator extends ItemsCalculator implements Calculator | |
{ | |
<<__Memoize>> | |
public function calculate() : ImmVector<int> | |
{ | |
return $this->items(); | |
} | |
} | |
final class NonMemoizeCalculator extends ItemsCalculator implements Calculator | |
{ | |
public function calculate() : ImmVector<int> | |
{ | |
return $this->items(); | |
} | |
} |
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
<?hh //partial | |
namespace example; | |
require_once __DIR__ . '/vendor/autoload.php'; | |
require_once __DIR__ . '/memoize.hh'; | |
memoize_main(); | |
non_memoize_main(); |
- MacBook Pro (Retina, 13-inch, Early 2015)
- 2.7 GHz Intel Core i5
- 16 GB 1867 MHz DDR3
seq | time | memory |
---|---|---|
1 | 13.29 ms | 20.77 KB |
2 | 6.90 ms | 0.00 KB |
3 | 5.84 ms | 0.00 KB |
4 | 4.34 ms | 0.00 KB |
5 | 6.49 ms | 0.00 KB |
6 | 5.09 ms | 0.00 KB |
7 | 6.49 ms | 0.00 KB |
8 | 6.53 ms | 0.00 KB |
9 | 5.81 ms | 0.00 KB |
10 | 5.33 ms | 0.00 KB |
11 | 5.98 ms | 0.00 KB |
12 | 5.86 ms | 0.00 KB |
13 | 5.84 ms | 0.00 KB |
14 | 7.17 ms | 0.00 KB |
15 | 6.36 ms | 0.00 KB |
seq | time | memory |
---|---|---|
1 | 14.70 ms | 6.14 KB |
2 | 10.32 ms | 0.00 KB |
3 | 10.04 ms | 0.00 KB |
4 | 10.05 ms | 0.00 KB |
5 | 8.99 ms | 0.00 KB |
6 | 9.56 ms | 0.00 KB |
7 | 8.80 ms | 0.00 KB |
8 | 12.67 ms | 0.00 KB |
9 | 11.23 ms | 0.00 KB |
10 | 10.01 ms | 0.00 KB |
11 | 11.22 ms | 0.00 KB |
12 | 11.38 ms | 0.00 KB |
13 | 9.71 ms | 0.00 KB |
14 | 9.94 ms | 0.00 KB |
15 | 10.10 ms | 0.00 KB |
seq | time | memory |
---|---|---|
1 | 30.35 ms | 24.50 KB |
2 | 22.61 ms | 0.00 KB |
3 | 22.27 ms | 0.00 KB |
4 | 24.91 ms | 0.00 KB |
5 | 20.30 ms | 0.00 KB |
6 | 19.70 ms | 0.00 KB |
7 | 19.83 ms | 0.00 KB |
8 | 19.60 ms | 0.00 KB |
9 | 20.05 ms | 0.00 KB |
10 | 19.73 ms | 0.00 KB |
11 | 19.84 ms | 0.00 KB |
12 | 19.70 ms | 0.00 KB |
13 | 22.65 ms | 0.00 KB |
14 | 20.83 ms | 0.00 KB |
15 | 22.15 ms | 0.00 KB |
seq | time | memory |
---|---|---|
1 | 37.06 ms | 9.71 KB |
2 | 28.91 ms | 0.00 KB |
3 | 29.93 ms | 0.00 KB |
4 | 29.53 ms | 0.00 KB |
5 | 30.97 ms | 0.00 KB |
6 | 28.17 ms | 0.00 KB |
7 | 28.70 ms | 0.00 KB |
8 | 30.39 ms | 0.00 KB |
9 | 30.59 ms | 0.00 KB |
10 | 33.03 ms | 0.00 KB |
11 | 33.88 ms | 0.00 KB |
12 | 29.91 ms | 0.00 KB |
13 | 31.27 ms | 0.00 KB |
14 | 29.00 ms | 0.00 KB |
15 | 29.92 ms | 0.00 KB |
seq | time | memory |
---|---|---|
1 | 22.72 ms | 8,221.35 KB |
2 | 0.55 ms | 0.83 KB |
3 | 0.01 ms | 0.00 KB |
4 | 0.00 ms | 0.00 KB |
5 | 0.00 ms | 0.00 KB |
6 | 0.00 ms | 0.00 KB |
7 | 0.00 ms | 0.00 KB |
8 | 0.00 ms | 0.00 KB |
9 | 0.00 ms | 0.00 KB |
10 | 0.00 ms | 0.00 KB |
11 | 0.00 ms | 0.00 KB |
12 | 0.00 ms | 0.00 KB |
13 | 0.00 ms | 0.00 KB |
14 | 0.00 ms | 0.00 KB |
15 | 0.00 ms | 0.00 KB |
seq | time | memory |
---|---|---|
1 | 10.70 ms | 3.27 KB |
2 | 7.48 ms | 0.00 KB |
3 | 7.39 ms | 0.00 KB |
4 | 7.16 ms | 0.00 KB |
5 | 7.08 ms | 0.00 KB |
6 | 7.92 ms | 0.00 KB |
7 | 6.13 ms | 0.00 KB |
8 | 8.59 ms | 0.00 KB |
9 | 6.73 ms | 0.00 KB |
10 | 8.67 ms | 0.00 KB |
11 | 5.99 ms | 0.00 KB |
12 | 7.86 ms | 0.00 KB |
13 | 7.21 ms | 0.00 KB |
14 | 7.09 ms | 0.00 KB |
15 | 7.18 ms | 0.00 KB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment