forked from mislav/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathirbrc
More file actions
executable file
·41 lines (35 loc) · 896 Bytes
/
irbrc
File metadata and controls
executable file
·41 lines (35 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# http://linux.die.net/man/1/irb
require 'irb/completion'
# IRB.conf[:AUTO_INDENT] = true
IRB.conf[:PROMPT_MODE] = :SIMPLE
require 'pp'
load File.dirname(__FILE__) + '/.railsrc' if $0 == 'irb' && ENV['RAILS_ENV']
def time(times = 1)
ret = nil
Benchmark.bm { |x| x.report { times.times { ret = yield } } }
ret
end
def copy(data)
File.popen('pbcopy', 'w') { |p| p << data.to_s }
$?.success?
end
if defined? Benchmark
class Benchmark::ReportProxy
def initialize(bm, iterations)
@bm = bm
@iterations = iterations
@queue = []
end
def method_missing(method, *args, &block)
args.unshift(method.to_s + ':')
@bm.report(*args) do
@iterations.times { block.call }
end
end
end
def compare(times = 1, label_width = 12)
Benchmark.bm(label_width) do |x|
yield Benchmark::ReportProxy.new(x, times)
end
end
end