Skip to content
Browse files

Add a bench for accessing a Java array from Ruby.

  • Loading branch information...
1 parent 763a753 commit 36d72b379abf41ddcd9573b2efb0f3a558db41c7 @headius headius committed May 10, 2009
Showing with 21 additions and 0 deletions.
  1. +21 −0 bench/java/bench_java_array.rb
View
21 bench/java/bench_java_array.rb
@@ -0,0 +1,21 @@
+require 'benchmark'
+require 'java'
+
+(ARGV[0] || 1).to_i.times {
+ Benchmark.bm(30) {|bm|
+ bm.report("control, ruby array") {
+ a = [1,2,3]
+ 1_000_000.times {
+ a[0]; a[0]; a[0]; a[0]; a[0]
+ a[0]; a[0]; a[0]; a[0]; a[0]
+ }
+ }
+ bm.report("java array") {
+ a = [1,2,3].to_java :int
+ 1_000_000.times {
+ a[0]; a[0]; a[0]; a[0]; a[0]
+ a[0]; a[0]; a[0]; a[0]; a[0]
+ }
+ }
+ }
+}

0 comments on commit 36d72b3

Please sign in to comment.
Something went wrong with that request. Please try again.