Module: Benchmarker

Defined in:
lib/benchmarker.rb

Defined Under Namespace

Modules: Color, Misc Classes: Benchmark, OptionParser, Result, Scope, Task, TaskError, TimeSet, ValidationFailed

Constant Summary collapse

VERSION =
"$Release: 1.0.0 $".split()[1]
N_REPEAT =

number of repeat (100 times)

100
OPTIONS =

ex: 1000, iter: 10, extra: 2, inverse: true

{}
TASK =
Task

Class Method Summary collapse

Class Method Details

.new(title = nil, **kwargs, &b) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/benchmarker.rb', line 20

def self.new(title=nil, **kwargs, &b)
  #; [!s7y6x] overwrites existing options by command-line options.
  kwargs.update(OPTIONS)
  #; [!2zh7w] creates new Benchmark object wit options.
  bm = Benchmark.new(title: title, **kwargs)
  return bm
end

.parse_cmdopts(argv = ARGV) ⇒ Object



959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# File 'lib/benchmarker.rb', line 959

def self.parse_cmdopts(argv=ARGV)
  #; [!348ip] parses command-line options.
  #; [!snqxo] exits with status code 1 if error in command option.
  options, keyvals = OptionParser.parse_options(argv) do |errmsg|
    $stderr.puts errmsg
    exit 1
  end
  #; [!p3b93] prints help message if '-h' or '--help' option specified.
  if options['h'] || keyvals['help']
    puts OptionParser.help_message()
    exit 0
  end
  #; [!iaryj] prints version number if '-v' option specified.
  if options['v']
    puts VERSION
    exit 0
  end
  #; [!nrxsb] prints sample code if '-S' option specified.
  if options['S']
    puts Misc.sample_code()
    exit 0
  end
  #; [!s7y6x] keeps command-line options in order to overwirte existing options.
  #; [!nexi8] option '-w' specifies task name width.
  #; [!raki9] option '-n' specifies count of loop.
  #; [!mt7lw] option '-i' specifies number of iteration.
  #; [!7f2k3] option '-x' specifies number of best/worst tasks removed.
  #; [!r0439] option '-I' specifies inverse switch.
  #; [!4c73x] option '-o' specifies outout JSON file.
  #; [!02ml5] option '-q' specifies quiet mode.
  #; [!e5hv0] option '-c' specifies colorize enabled.
  #; [!eb5ck] option '-C' specifies colorize disabled.
  #; [!6nxi8] option '-s' specifies sleep time.
  #; [!muica] option '-F' specifies filter.
  OPTIONS[:width]    = options['w'] if options['w']
  OPTIONS[:loop]     = options['n'] if options['n']
  OPTIONS[:iter]     = options['i'] if options['i']
  OPTIONS[:extra]    = options['x'] if options['x']
  OPTIONS[:inverse]  = options['I'] if options['I']
  OPTIONS[:outfile]  = options['o'] if options['o']
  OPTIONS[:quiet]    = options['q'] if options['q']
  OPTIONS[:colorize] = true         if options['c']
  OPTIONS[:colorize] = false        if options['C']
  OPTIONS[:sleep]    = options['s'] if options['s']
  OPTIONS[:filter]   = options['F'] if options['F']
  #; [!3khc4] sets global variables if long option specified.
  keyvals.each {|k, v| eval "$opt_#{k} = #{v.inspect}" }
  #
  return options, keyvals  # for testing
end

.scope(title = nil, **kwargs, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/benchmarker.rb', line 28

def self.scope(title=nil, **kwargs, &block)
  #; [!4f695] creates Benchmark object, define tasks, and run them.
  bm = self.new(title, **kwargs)
  bm.scope(&block)
  bm.run()
  return bm
end