require 'rubygems' require 'bundler/setup' require 'v8' require 'benchmark' require 'optparse' OPTIONS = { :times => 5, :mode => :object, :objects => 500 } parser = OptionParser.new do |opts| opts.on("-t", "--times [T]", Integer, "run benchmark N times") do |t| OPTIONS[:times] = t end opts.on("-m", "--mode [MODE]", [:object, :function, :eval], "select the type of object access to stress test") do |mode| mode = mode.to_sym raise "unsupported mode #{mode}" unless [:object,:function,:eval].include?(mode) OPTIONS[:mode] = mode end opts.on("-o", "--objects [N]", Integer, "create N objects for each iteration") do |n| OPTIONS[:objects] = n end opts end parser.parse! ARGV MODE = OPTIONS[:mode] TIMES = OPTIONS[:times] OBJECTS = OPTIONS[:objects] puts "using #{OPTIONS[:mode]}" if MODE==:object def get(i) @cxt["test"]["objects"][i] end elsif MODE==:function def get(i) @cxt["test"].getObject(i) end elsif MODE==:eval def get(i) @cxt.eval "test.getObject(#{i})" end end js= <>> 19)) & 0xffffffff; test.seed = ((test.seed + 0x165667b1) + (test.seed << 5)) & 0xffffffff; test.seed = ((test.seed + 0xd3a2646c) ^ (test.seed << 9)) & 0xffffffff; test.seed = ((test.seed + 0xfd7046c5) + (test.seed << 3)) & 0xffffffff; test.seed = ((test.seed ^ 0xb55a4f09) ^ (test.seed >>> 16)) & 0xffffffff; return (test.seed & 0xfffffff) / 0x10000000; }; test.init = function() { test.objects = []; for(var i=0; i<#{OBJECTS}; i++) { var hash = {}; for(var j=0; j<10; j++) { var isString = test.random(); var key = "str" + test.random(); var value; if(isString < 0.5) value = "str" + test.random(); else value = test.random(); hash[key] = value; } test.objects[i] = hash; } return test.objects.length; } test.findSum = function() { test.summ = 0; var length = test.objects.length; for(var i=0; i