benchmarks/methodinvocation.rb
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 10 Sep 2013 10:25:34 +0100
branchdevelopment
changeset 2723 02802ba0024f
parent 2599 388b25528e07
child 2731 13f5be2bf83b
permissions -rwxr-xr-x
Added JavaSourceParser - a base class for JavaSyntaxHighlighter.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2598
94ae3f5f4df1 adding ruby benchmarks for comparison
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
diff changeset
     1
#!/usr/bin/env ruby
2599
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
     2
require 'benchmark'
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
     3
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
     4
class MethodInvocation
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
     5
  def do_smth
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
     6
    self
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
     7
  end
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
     8
end
2598
94ae3f5f4df1 adding ruby benchmarks for comparison
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents:
diff changeset
     9
2599
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    10
results = Benchmark.bmbm do |bm|
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    11
  raise "Expecting one arg - num of invocations" if ARGV.size == 0
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    12
  n = ARGV[0].to_i
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    13
  inst = MethodInvocation.new
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    14
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    15
  bm.report do 
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    16
    n.times { inst.do_smth }
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    17
  end
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    18
end
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    19
puts "EXECUTION TIME: #{results[0].real * 1000.0}"
388b25528e07 implement method invocation rb benchmark
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 2598
diff changeset
    20