1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

update benchmarks to use the high-level Ruby API

thanks to @socialquantum for providing them in
#167
This commit is contained in:
Charles Lowell 2012-06-19 08:28:17 -05:00
parent 3c6c0c5a5d
commit 9bc5c2b510

View file

@ -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."