Permalink
Browse files

Move benchmark suite into its own directory, spruce things up a bit, …

…and add 'rake benchmark' to build and run the benchmark suite
  • Loading branch information...
1 parent 3b1b470 commit 3a5875f28cdb356ac2cb1d7c331617b7c57ace13 Tony Arcieri committed Aug 27, 2010
View
@@ -0,0 +1 @@
+**/*.reb
View
@@ -92,9 +92,23 @@ task :test => :build do
sh "bin/reia test/runner.re"
end
+# Benchmarks
+BENCHMARK_SRC = FileList.new('benchmarks/**/*.erl')
+BENCHMARK_DEST = BENCHMARK_SRC.map { |input| output_file(input, 'benchmarks/ebin/') }
+
+BENCHMARK_SRC.each do |input|
+ file output_file(input, 'benchmarks/ebin/') => input do
+ sh "erlc +debug_info -o benchmarks/ebin #{input}"
+ end
+end
+
+task :benchmark => BENCHMARK_DEST do
+ sh "bin/reia benchmarks/runner.re"
+end
+
# Cleaning
CLEAN.include %w(src/compiler/reia_scan.erl src/compiler/reia_parse.erl)
-CLEAN.include %w(ebin/* **/*.reb)
+CLEAN.include %w(**/*.beam **/*.reb)
#
# Installing
@@ -0,0 +1 @@
+*.beam
View
@@ -0,0 +1,42 @@
+# run benchmarks in Reia and Erlang
+
+started_at = erl.now()
+Main.load("test/test_helper.re")
+
+benchmarks = ["recursion", "sleep", "forloops", "doloops"]
+bench_repeat = 10
+
+Main.puts("Running benchmark tests #{bench_repeat} times each")
+bench = benchmarks.map do |name|
+ Main.load("benchmarks/#{name}_benchmark.re")
+
+ erl_module = "benchmarks/ebin/#{name}_benchmark"
+ case erl.code.load_abs(erl_module.to_list())
+ when (:error, error)
+ throw("Couldn't load #{erl_module}: #{error}")
+ end
+
+ mod = "#{name.capitalize()}Benchmark".to_module()
+ reia_bench_start = erl.now()
+ (1..bench_repeat).to_list().map do |n|
+ mod.run()
+ end
+ reia_bench_end = erl.now()
+
+ erl_bench_start = erl.now()
+ (1..bench_repeat).to_list().map do |n|
+ erl.apply("#{name}_benchmark".to_atom(), :run, [])
+ end
+ erl_bench_end = erl.now()
+
+ reia_duration = TestHelper.duration(reia_bench_start, reia_bench_end)
+ erl_duration = TestHelper.duration(erl_bench_start, erl_bench_end)
+ ratio = reia_duration / erl_duration
+ Main.puts("#{name} Reia:#{reia_duration}s Erlang:#{erl_duration}s that's #{ratio}x slower")
+end
+
+finished_at = erl.now()
+
+duration = TestHelper.duration(started_at, finished_at)
+Main.puts("\nFinished in #{duration} seconds\n")
+Main.puts("#{bench.size()} benchmarks")
File renamed without changes.
View
@@ -20,10 +20,6 @@ tests = [
("lib", ["json"])
]
-benchmarks = [
- "recursion", "sleep", "forloops", "doloops"
-]
-
results = tests.map do |(group, modules)|
modules.map do |name|
try
@@ -56,37 +52,9 @@ errors.each do |(:error, test, ex)|
end
end
-# run benchmarks in Reia and Erlang
-
-bench_repeat = 10
-
-Main.puts("Running benchmark tests #{bench_repeat} times each")
-bench = benchmarks.map do |name|
- Main.load("test/benchmarks/#{name}_benchmark.re")
- mod = "#{name.capitalize()}Benchmark".to_module()
- reia_bench_start = erl.now()
- (1..bench_repeat).to_list().map do |n|
- mod.run()
- end
- reia_bench_end = erl.now()
-
- erl_bench_start = erl.now()
- (1..bench_repeat).to_list().map do |n|
- erl.apply("#{name}_benchmark".to_atom(), :run, [])
- end
- erl_bench_end = erl.now()
-
- reia_duration = TestHelper.duration(reia_bench_start, reia_bench_end)
- erl_duration = TestHelper.duration(erl_bench_start, erl_bench_end)
- ratio = reia_duration / erl_duration
- Main.puts("#{name} Reia:#{reia_duration}s Erlang:#{erl_duration}s that's #{ratio}x slower")
-end
-
finished_at = erl.now()
-
duration = TestHelper.duration(started_at, finished_at)
-Main.puts("\nFinished in #{duration} seconds\n")
-Main.puts("#{results.size()} assertions, #{benchmarks.size()} benchmarks, #{failures.size()} failures, #{errors.size()} errors\n")
-Main.puts("#{bench.size()} benchmarks")
+Main.puts("Finished in #{duration} seconds\n")
+Main.puts("#{results.size()} assertions, #{failures.size()} failures, #{errors.size()} errors")
System.halt(1) if failures.size() > 0 or errors.size() > 0

0 comments on commit 3a5875f

Please sign in to comment.