Sha256: f2ec83f745e104d5d966f24241145fba18a1adc2c01fe2221d7dcf1583ec02e3

Contents?: true

Size: 865 Bytes

Versions: 2

Compression:

Stored size: 865 Bytes

Contents

# 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.open('test/test_pygments.rb').read.to_s * repeats

puts "Benchmarking....\n"
puts 'Size: ' + code.bytesize.to_s + " bytes\n"
puts 'Iterations: ' + num.to_s + "\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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pygments.rb-2.2.0 bench.rb
pygments.rb-2.1.0 bench.rb