benchmark Pygments from Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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