Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 21 lines (16 sloc) 0.825 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
require File.join(File.dirname(__FILE__), '/lib/pygments.rb')
require 'benchmark'

include 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_data.py').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 ") { for i in 1..num; Pygments.highlight(code, :lexer => 'python'); end }
  x.report("pygments popen (process already started) ") { for i in 1..num; Pygments.highlight(code, :lexer => 'python'); end }
  x.report("pygments popen (process already started 2) ") { for i in 1..num; Pygments.highlight(code, :lexer => 'python'); end }
end
Something went wrong with that request. Please try again.