Skip to content

Instantly share code, notes, and snippets.

@jfirebaugh
Created May 13, 2011 21:03
Show Gist options
  • Select an option

  • Save jfirebaugh/971319 to your computer and use it in GitHub Desktop.

Select an option

Save jfirebaugh/971319 to your computer and use it in GitHub Desktop.
require 'java'
require 'benchmark'
require 'rubygems'
require 'json/common'
require 'json/ext/parser'
def foo
Benchmark.measure {
sc = org.jruby.embed.ScriptingContainer.new(org.jruby.embed.LocalContextScope::THREADSAFE)
sc.runScriptlet("require 'rubygems'")
sc.runScriptlet("require 'json/common'")
sc.runScriptlet("require 'json/ext/parser'")
sc.clear
sc.terminate
sc = nil
}
end
i = 0
puts RUBY_DESCRIPTION
while(true)
i += 1
t = foo
JRuby.gc
printf "loop: %3d time: %*.4f mem: %10d\n", i, 7, t.total, Java::JavaLang::Runtime.getRuntime.totalMemory
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment