Skip to content

Instantly share code, notes, and snippets.

@nathany
Created March 30, 2010 19:40
Show Gist options
  • Select an option

  • Save nathany/349504 to your computer and use it in GitHub Desktop.

Select an option

Save nathany/349504 to your computer and use it in GitHub Desktop.
benchmark Pygments from Python
# benchmark Pygments from Python
# http://github.com/ryanb/railscasts-episodes/blob/master/episode-207/syntax_benchmarks.rb
from pygments import highlight
from pygments.lexers import RubyLexer
from pygments.formatters import HtmlFormatter
import timeit
# run it once to initialize
highlight("print 'hello'", RubyLexer(), HtmlFormatter())
file = open('syntax_benchmarks.rb')
code = file.read()
t = timeit.Timer("highlight(code, RubyLexer(), HtmlFormatter())", "gc.enable(); from __main__ import highlight, code, RubyLexer, HtmlFormatter")
print "%.6f usec" % t.timeit(50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment