-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathbench.rb
More file actions
28 lines (22 loc) · 832 Bytes
/
bench.rb
File metadata and controls
28 lines (22 loc) · 832 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
# frozen_string_literal: true
require File.join(File.dirname(__FILE__), '/lib/pygments.rb')
require 'benchmark'
# number of iterations
num = ARGV[0] ? ARGV[0].to_i : 10
# we can also repeat the code itself
repeats = ARGV[1] ? ARGV[1].to_i : 1
code = File.read('test/test_pygments.rb') * repeats
puts "Benchmarking....\n"
puts "Size: #{code.bytesize} bytes\n"
puts "Iterations: #{num}\n"
Benchmark.bm(40) do |x|
x.report('pygments popen ') do
(1..num).each { |_i|; Pygments.highlight(code, lexer: 'python') }
end
x.report('pygments popen (process already started) ') do
(1..num).each { |_i|; Pygments.highlight(code, lexer: 'python') }
end
x.report('pygments popen (process already started 2) ') do
(1..num).each { |_i|; Pygments.highlight(code, lexer: 'python') }
end
end