forked from mislav/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
irbrc
41 lines (35 loc) · 865 Bytes
/
irbrc
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
#!/usr/bin/ruby
require 'irb/completion'
# IRB.conf[:AUTO_INDENT] = true
require 'pp'
require 'rubygems'
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