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
- .new(title = nil, **kwargs, &b) ⇒ Object
- .parse_cmdopts(argv = ARGV) ⇒ Object
- .scope(title = nil, **kwargs, &block) ⇒ Object
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. , keyvals = OptionParser.(argv) do |errmsg| $stderr.puts errmsg exit 1 end #; [!p3b93] prints help message if '-h' or '--help' option specified. if ['h'] || keyvals['help'] puts OptionParser.() exit 0 end #; [!iaryj] prints version number if '-v' option specified. if ['v'] puts VERSION exit 0 end #; [!nrxsb] prints sample code if '-S' option specified. if ['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] = ['w'] if ['w'] OPTIONS[:loop] = ['n'] if ['n'] OPTIONS[:iter] = ['i'] if ['i'] OPTIONS[:extra] = ['x'] if ['x'] OPTIONS[:inverse] = ['I'] if ['I'] OPTIONS[:outfile] = ['o'] if ['o'] OPTIONS[:quiet] = ['q'] if ['q'] OPTIONS[:colorize] = true if ['c'] OPTIONS[:colorize] = false if ['C'] OPTIONS[:sleep] = ['s'] if ['s'] OPTIONS[:filter] = ['F'] if ['F'] #; [!3khc4] sets global variables if long option specified. keyvals.each {|k, v| eval "$opt_#{k} = #{v.inspect}" } # return , 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 |