diff --git a/benchmarks.rb b/benchmarks.rb index 4bb8edc..6c21ae5 100644 --- a/benchmarks.rb +++ b/benchmarks.rb @@ -116,75 +116,70 @@ end -def call_test(suite, name, times = 1) - cxt = nil - V8::C::HandleScope() do - cxt = suite.CreationContext() - cxt.Enter() - times.times do - test = suite.Get(V8::C::String::New(name)) - test.Call(suite, 0, []) - end - end -ensure - cxt.Exit() if cxt -end + #RubyProf.measure_mode = RubyProf::CPU_TIME puts "init js context..." cxt = V8::Context.new cxt.eval(js) -suite = cxt.eval('var test = createTest(); test;') +cxt.eval('var test = createTest()') puts "run init test" result =profile do - call_test suite, 'init', TIMES + TIMES.times do + cxt['test'].init() + end end puts "init time: #{get_res(result) / TIMES} sec." puts "run findSum test" -call_test(suite, 'init') - +cxt['test'].init() result =profile do - call_test suite, 'findSum', TIMES + TIMES.times do + cxt['test'].findSum + end end puts "findSum time: #{get_res(result) / TIMES} sec." puts "run Objects iversion in ruby test" -call_test suite, 'init' +cxt['test'].init() result =profile do - cxt.native.Enter() - V8::C::HandleScope() do - TIMES.times do |j| - for i in 0..(OBJECTS-1) do - obj = suite.Get(V8::C::String::New("objects")).Get(i) - names = obj.GetPropertyNames() - for k in 0..names.Length() - 1 do - name = names.Get(k) - value = obj.Get(name) - if value.instance_of? Float - value = value * -1 - end - suite.Get(V8::C::String::New("objects")).Set(i, obj) + TIMES.times do |j| + puts j + for i in 0..(OBJECTS-1) do + + obj = cxt["test"]["objects"][i] + begin + obj.each do |key, value| + if value.instance_of? Float + value = value * (-1) end end + + cxt["test"]["objects"][i] = obj + rescue + puts "ex!" + end + end + end - cxt.native.Exit() end puts "Objects time: #{get_res(result) / TIMES} sec." puts "run finalCheck test" -call_test suite, 'init' +cxt['test'].init() result =profile do - call_test suite, 'finalCheck', TIMES + TIMES.times do + cxt['test'].finalCheck + end end puts "final check time: #{get_res(result) / TIMES} sec." \ No newline at end of file