Skip to content

Instantly share code, notes, and snippets.

@nathany
Created March 30, 2010 19:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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