Skip to content

Instantly share code, notes, and snippets.

View BanzaiMan's full-sized avatar

Hiro Asari BanzaiMan

View GitHub Profile
surfboard:~$ sudo dtrace -l | grep ruby
21381 ruby5542 libruby.1.9.1.dylib garbage_collect gc-begin
21382 ruby5542 libruby.1.9.1.dylib garbage_collect gc-end
21383 ruby5542 libruby.1.9.1.dylib vm_exec_core insn-entry
21384 ruby5542 libruby.1.9.1.dylib vm_exec_core insn-return
21385 ruby5542 libruby.1.9.1.dylib vm_exec_core line
21386 ruby5542 libruby.1.9.1.dylib vm_exec_core method-entry
21387 ruby5542 libruby.1.9.1.dylib vm_exec_core method-return
21388 ruby5542 libruby.1.9.1.dylib struct_alloc object-create
21389 ruby5542 libruby.1.9.1.dylib str_alloc object-create
surfboard:~$ ruby1.9 -e 'p Marshal.dump(34131348341.384172394817324)'
"\x04\bf\x1A34131348341.384171\x00\x89d"
surfboard:~$ jruby --1.9 -e 'p Marshal.load("\x04\bf\x1A34131348341.384171\x00\x89d")'
34131348341.3842
surfboard:~$ ruby1.9 -e 'p Marshal.load(Marshal.dump(34131348341.384172394817324))'
34131348341.38417
$ jruby -v -rdate -e 'p Date.new'
jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-02-17 c86ed17) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]
#<Date: -1/2,0,2299161>
$ /usr/local/torquebox-current/jruby/bin/jruby -v -rdate -e 'p Date.new'
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]
#<Date: -1/2,0,2299161>
aotearoa:jruby_test$ unset JRUBY_OPTS
aotearoa:jruby_test$ cat jruby-shebang.rb
#!/usr/bin/env jruby -J-Djruby.debug.loadService.timing=true
require 'rubygems'
aotearoa:jruby_test$ ./jruby-shebang.rb
-> builtin/core_ext/symbol
<- builtin/core_ext/symbol - 38ms
-> enumerator
<- enumerator - 4ms
@BanzaiMan
BanzaiMan / gist:321454
Created March 4, 2010 06:23
Simple GC statistics in JRuby
require 'java'
gcb = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans()
p gcb.inject(0) {|s,gc| s+gc.getCollectionCount}
p gcb.inject(0) {|s,gc| s+gc.getCollectionTime}
C:\Users\asari\Documents\Development\jruby>ant spec
Buildfile: C:\Users\asari\Documents\Development\jruby\build.xml
init:
jar:
init:
extract-rdocs:
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] java.lang.RuntimeException: Error running script
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] at org.jruby.JRubyApplet.init(JRubyApplet.java:239)
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] at sun.applet.AppletPanel.run(AppletPanel.java:424)
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] at java.lang.Thread.run(Thread.java:637)
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] at org.jruby.runtime.ThreadContext.getCurrentScope(ThreadContext.java:194)
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] at org.jruby.Ruby.evalScriptlet(Ruby.java:285)
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] at org.jruby.JRubyApplet$2.run(JRubyApplet.java:233)
3/12/10 4:39:39 PM [0x0-0x1db1db].com.apple.Safari[34721] at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
3
require File.expand_path('../../../spec_helper', __FILE__)
require 'nkf'
describe "NKF.guess" do
it "guesses encoding of a String in JIS" do
NKF.guess("\e$B$^$D$b$H$f$-$R$m\e(B").should == NKF::JIS
end
it "guesses encoding of a String in EUC" do
NKF.guess("\244\336\244\304\244\342\244\310\244\346\244\255\244\322\244\355").should == NKF::EUC
end
aotearoa:bench[git:master]$ jruby -v
jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-03-18 646afea) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]
aotearoa:bench[git:master]$ jruby png_type_6.rb
Rehearsal ----------------------------------------------
PNG Type 6 7.754000 0.000000 7.754000 ( 7.679000)
------------------------------------- total: 7.754000sec
user system total real
PNG Type 6 6.713000 0.000000 6.713000 ( 6.713000)
aotearoa:bench[git:master]$ jruby --fast png_type_6.rb
require File.dirname(__FILE__) + "/../spec_helper"
TEST_VALUE = 101
class MyCallableTask
include java.util.concurrent.Callable
def call
sleep 2
TEST_VALUE