Skip to content

Instantly share code, notes, and snippets.

@jruby
Created December 30, 2009 22:26
Show Gist options
  • Save jruby/266455 to your computer and use it in GitHub Desktop.
Save jruby/266455 to your computer and use it in GitHub Desktop.
~/projects/jruby ➔ jirb
irb(main):001:0> require 'java'
=> true
irb(main):002:0> 'foo'.to_java.class
=> Java::JavaLang::String
irb(main):003:0> 1.to_java.class
=> Java::JavaLang::Long
irb(main):004:0> [1,2,3].to_java.class
=> #<Class:01xb95f72>
irb(main):005:0> Object.new.to_java.class
=> Java::OrgJruby::RubyObject
irb(main):006:0> STDIN.to_java.class
=> Java::OrgJruby::RubyIO
~/projects/jruby ➔ jruby -rjava -rbenchmark -e "import java.lang.System; 10.times { puts Benchmark.measure { a = 'foo'; 1_000_000.times { System.get_property a } } }
> "
1.122000 0.000000 1.122000 ( 1.098000)
1.069000 0.000000 1.069000 ( 1.069000)
1.056000 0.000000 1.056000 ( 1.056000)
1.081000 0.000000 1.081000 ( 1.081000)
1.057000 0.000000 1.057000 ( 1.057000)
1.056000 0.000000 1.056000 ( 1.056000)
1.055000 0.000000 1.055000 ( 1.055000)
1.060000 0.000000 1.060000 ( 1.061000)
1.072000 0.000000 1.072000 ( 1.072000)
1.071000 0.000000 1.071000 ( 1.071000)
~/projects/jruby ➔ jruby -rjava -rbenchmark -e "import java.lang.System; 10.times { puts Benchmark.measure { a = 'foo'.to_java; 1_000_000.times { System.get_property a } } }
"
0.880000 0.000000 0.880000 ( 0.857000)
0.800000 0.000000 0.800000 ( 0.800000)
0.796000 0.000000 0.796000 ( 0.796000)
0.797000 0.000000 0.797000 ( 0.797000)
0.801000 0.000000 0.801000 ( 0.801000)
0.799000 0.000000 0.799000 ( 0.799000)
0.803000 0.000000 0.803000 ( 0.803000)
0.801000 0.000000 0.801000 ( 0.801000)
0.806000 0.000000 0.806000 ( 0.806000)
0.815000 0.000000 0.815000 ( 0.815000)
~/projects/jruby ➔ jruby -rjava -rbenchmark -e "import java.lang.System; 10.times { puts Benchmark.measure { a = 'foo'.to_java; 1_000_000.times { System } } }
"
0.325000 0.000000 0.325000 ( 0.302000)
0.275000 0.000000 0.275000 ( 0.275000)
0.279000 0.000000 0.279000 ( 0.279000)
0.274000 0.000000 0.274000 ( 0.274000)
0.279000 0.000000 0.279000 ( 0.279000)
0.279000 0.000000 0.279000 ( 0.279000)
0.279000 0.000000 0.279000 ( 0.280000)
0.276000 0.000000 0.276000 ( 0.277000)
0.274000 0.000000 0.274000 ( 0.274000)
0.274000 0.000000 0.274000 ( 0.274000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment