Created
March 11, 2010 18:58
-
-
Save yokolet/329513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package vanilla; | |
import java.util.Date; | |
import org.jruby.RubyClass; | |
import org.jruby.RubyObject; | |
import org.jruby.embed.AttributeName; | |
import org.jruby.embed.LocalContextScope; | |
import org.jruby.embed.LocalVariableBehavior; | |
import org.jruby.embed.ScriptingContainer; | |
public class CallMethodToCompare { | |
private CallMethodToCompare() { | |
ScriptingContainer l_container = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.TRANSIENT); | |
l_container.runScriptlet("class Driver \n" + | |
" def test= value \n" + | |
" @test = value \n" + | |
" end \n" + | |
" def test \n" + | |
" @test \n" + | |
" end \n" + | |
"end \n "); | |
RubyClass l_driver = (RubyClass)l_container.runScriptlet("Driver"); | |
RubyObject l_obj1 = (RubyObject) l_container.callMethod(l_driver, "new"); | |
l_container.setAttribute(AttributeName.SHARING_VARIABLES, false); | |
long time1 = new Date().getTime(); | |
containerMethod(l_container, l_driver); | |
long time2 = new Date().getTime(); | |
System.out.println(time2 - time1); | |
objectMethod(l_driver); | |
long time3 = new Date().getTime(); | |
System.out.println(time3 - time2); | |
} | |
private void containerMethod(ScriptingContainer container, RubyClass l_driver) { | |
for (int i=0; i< 5000; i++) { | |
RubyObject l_obj1 = (RubyObject) container.callMethod(l_driver, "new"); | |
container.terminate(); | |
} | |
} | |
private void objectMethod(RubyClass l_driver) { | |
for (int i=0; i< 5000; i++) { | |
RubyObject l_obj2 = (RubyObject) l_driver.callMethod("new"); | |
} | |
} | |
public static void main(String[] argv) { | |
new CallMethodToCompare(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment