-
Notifications
You must be signed in to change notification settings - Fork 0
/
shootout_adapter.rb
61 lines (49 loc) · 1.36 KB
/
shootout_adapter.rb
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class ShootoutAdapter
def self.load libraries
libraries.map do |library_and_subversion|
library, subversion = library_and_subversion.split(':', 2)
library = library.gsub(/\W/, '')
require_relative "adapters/#{library.downcase}"
Adapters.const_get(library).new(subversion)
end
end
attr :subversion
def initialize subversion = nil
@subversion = subversion
end
def library
self.class::LIBRARY
end
def version
library::VERSION
end
def name
"#{library.name}#{" (#{subversion})" if subversion}".strip
end
def benchmark file, source, language, format, repeats, disable_gc
language += subversion if subversion
# warmup and check
unless highlight file, "test\n<42>", language, format
return
end
GC.disable if disable_gc
require 'profile' if ENV['PROFILE']
# benchmark
time = Benchmark.realtime do
repeats.times do
@result = highlight file, source, language, format
end
end
time / repeats
ensure
GC.enable && GC.start if disable_gc
end
def highlight file, source, language, format
end
def fast_ruby
# loading bundler results in something like:
# RUBYOPT=-I~/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib -rbundler/setup
# which slows down ruby considerably. Use this one instead.
'RUBYOPT= ruby'
end
end