Skip to content
This repository
Browse code

Added benchmark

  • Loading branch information...
commit b982009c298400a1661e1ebaa154d9eaf81cb6d7 1 parent f79d830
Claudio Bustos authored
70 benchmark/benchmark.rb
... ... @@ -0,0 +1,70 @@
  1 +# Compares rserve, rinruby and rsruby
  2 +# in retrieval and assign of information
  3 +$:.unshift(File.dirname(__FILE__)+"/../lib")
  4 +
  5 +require 'rubygems'
  6 +require 'rserve'
  7 +require 'rinruby'
  8 +require 'benchmark'
  9 +data_size=10000
  10 +tries=50
  11 +con=Rserve::Connection.new
  12 +data=data_size.times.map {rand()}
  13 +data_integer=data_size.times.map {rand(100)}
  14 +Benchmark.bm(30) do |x|
  15 + x.report("assign '1' rinruby") {
  16 + tries.times {
  17 + R.a=1
  18 + }
  19 + }
  20 + x.report("assign '1' rserve") {
  21 + con.assign("a", 1)
  22 + }
  23 +
  24 + x.report("assign double(#{data_size}) rinruby") {
  25 + tries.times {
  26 + R.a=data
  27 + }
  28 + }
  29 + x.report("assign double(#{data_size}) rserve") {
  30 + con.assign("a", data)
  31 + }
  32 +
  33 + x.report("void_eval rinruby") {
  34 + tries.times {
  35 + R.eval("1",false)
  36 + }
  37 + }
  38 + x.report("void_eval rserve") {
  39 + tries.times {
  40 + con.void_eval("1")
  41 + }
  42 + }
  43 + # Assign data
  44 + R.a=1
  45 + con.assign('a',1)
  46 + x.report("get '1' rinruby") {
  47 + tries.times {
  48 + R.pull('a')
  49 + }
  50 + }
  51 + x.report("get '1' rserve") {
  52 + tries.times {
  53 + con.eval('a').to_ruby
  54 + }
  55 + }
  56 +
  57 + R.a=data
  58 + con.assign('a',data)
  59 +
  60 + x.report("get double(#{data_size}) rinruby") {
  61 + tries.times {
  62 + R.pull('a')
  63 + }
  64 + }
  65 + x.report("get double(#{data_size}) rserve") {
  66 + tries.times {
  67 + con.eval('a').to_ruby
  68 + }
  69 + }
  70 +end
BIN  benchmark/comparison_2010_06_07.xls
Binary file not shown
45 benchmark/plot.rb
... ... @@ -0,0 +1,45 @@
  1 +# Creates a graph with multiple size assignment and retrieval
  2 +
  3 +require 'rubygems'
  4 +require 'rserve'
  5 +require 'rinruby'
  6 +require 'benchmark'
  7 +require 'statsample'
  8 +
  9 +max=40
  10 +
  11 +con=Rserve::Connection.new
  12 +rserve_assign = []
  13 +rserve_retrieve = []
  14 +rinruby_assign = []
  15 +rinruby_retrieve = []
  16 +max.times.map {|x|
  17 + puts "Rserve #{x}"
  18 + start=Time.new.to_f
  19 + con.assign('a',(x*100+1).times.map {rand})
  20 + a=Time.new.to_f-start
  21 +
  22 + start=Time.new.to_f
  23 +
  24 + con.eval('a').to_f
  25 +
  26 + b=Time.new.to_f-start
  27 +
  28 + rserve_assign.push(a)
  29 + rserve_retrieve.push(b)
  30 +}
  31 +rinruby=max.times.map {|x|
  32 +
  33 + puts "Rinruby #{x}"
  34 + start=Time.new.to_f
  35 + R.assign("a", (x*100+1).times.map {rand})
  36 + a=Time.new.to_f-start
  37 + start=Time.new.to_f
  38 + R.pull('a')
  39 + b=Time.new.to_f-start
  40 + rinruby_assign.push(a)
  41 + rinruby_retrieve.push(b)
  42 +}
  43 +
  44 +ds_assign={'times'=>(1..max).map {|v| v*100+1}.to_scale,'rserve assign'=> rserve_assign.to_scale, 'rserve retrieve'=>rserve_retrieve.to_scale, 'rinruby assign'=>rinruby_assign.to_scale, 'rinruby retrieve'=>rinruby_retrieve.to_scale}.to_dataset
  45 +Statsample::CSV.write(ds_assign,'comparison.csv')

0 comments on commit b982009

Please sign in to comment.
Something went wrong with that request. Please try again.