-
Notifications
You must be signed in to change notification settings - Fork 21
/
benchmark.rb
100 lines (73 loc) · 1.51 KB
/
benchmark.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true
require 'benchmark/ips'
# - - -
require_relative 'lib/paint'
require 'rainbow'
require 'rainbow/version'
require 'term/ansicolor'
require 'pastel'
pastel = Pastel.new
require 'ansi/code'
require 'ansi/version'
require 'hansi'
require 'hansi/version'
# - - -
puts "# TERMINAL ANSI COLORS BENCHMARK"
puts
puts " ruby: #{ RUBY_VERSION }"
puts " paint: #{ Paint::VERSION }"
puts " rainbow: #{ Rainbow::VERSION }"
puts " term/ansicolor #{ Term::ANSIColor::VERSION }"
puts " pastel #{ Pastel::VERSION }"
puts " ansi #{ ANSI::VERSION }"
puts " hansi #{ Hansi::VERSION }"
puts
puts "## ONLY FOREGROUND COLOR"
puts
# - - -
Benchmark.ips do |x|
x.report("paint"){
Paint['ANSI', :red]
}
x.report("paint w/ nesting"){
Paint%['ANSI', :red]
}
x.report("rainbow"){
Rainbow('ANSI').color(:red)
}
x.report("term/ansicolor"){
Term::ANSIColor.red('ANSI')
}
x.report("pastel"){
pastel.red('ANSI')
}
x.report("ansi"){
ANSI::Code.red('ANSI')
}
x.report("hansi"){
Hansi.render(:red, 'ANSI')
}
x.compare!
end
# - - -
puts
puts "## FOREGROUND + BACKGROUND COLOR"
puts
Benchmark.ips do |x|
x.report("paint"){
Paint['ANSI', :red, :green]
}
x.report("paint w/ nesting"){
Paint%['ANSI', :red, :green]
}
x.report("rainbow"){
Rainbow('ANSI').fg(:red).bg(:green)
}
x.report("term/ansicolor"){
Term::ANSIColor.red(Term::ANSIColor.on_green('ANSI'))
}
x.report("pastel"){
pastel.red.on_green('ANSI')
}
x.compare!
end