This repository has been archived by the owner on May 12, 2018. It is now read-only.
forked from pygments/pygments.rb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
13,812 additions
and
865 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ ext/Makefile | |
lib/pygments_ext.* | ||
tmp | ||
pkg | ||
*.pyc |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,22 @@ | ||
$:.unshift('lib') | ||
|
||
require File.join(File.dirname(__FILE__), '/lib/pygments.rb') | ||
require 'benchmark' | ||
require 'pygments/c' | ||
require 'pygments/ffi' | ||
require 'rubygems' | ||
require 'albino' | ||
|
||
num = ARGV[0] ? ARGV[0].to_i : 25 | ||
code = File.read(__FILE__) | ||
include Benchmark | ||
# number of iterations | ||
num = ARGV[0] ? ARGV[0].to_i : 10 | ||
|
||
albino, pygments, ffi = | ||
Albino.new(code, :ruby, :html).colorize, | ||
Pygments::C.highlight(code, :lexer => 'ruby'), | ||
Pygments::FFI.highlight(code, :lexer => 'ruby') | ||
# we can also repeat the code itself | ||
repeats = ARGV[1] ? ARGV[1].to_i : 1 | ||
|
||
unless albino == pygments and pygments == ffi | ||
raise "incompatible implementations (#{albino.size} != #{pygments.size} != #{ffi.size})" | ||
end | ||
code = File.open('test/test_data.py').read.to_s * repeats | ||
|
||
Benchmark.bm(25) do |x| | ||
x.report('albino') do | ||
num.times do | ||
Albino.new(code, :ruby, :html).colorize | ||
end | ||
end | ||
x.report('pygments::c') do | ||
num.times do | ||
Pygments::C.highlight(code, :lexer => 'ruby') | ||
end | ||
end | ||
x.report('pygments::ffi + reload') do | ||
num.times do | ||
Pygments::FFI.start | ||
Pygments::FFI.highlight(code, :lexer => 'ruby') | ||
Pygments::FFI.stop | ||
end | ||
end | ||
Pygments::FFI.start | ||
x.report('pygments::ffi') do | ||
num.times do | ||
Pygments::FFI.highlight(code, :lexer => 'ruby') | ||
end | ||
end | ||
end | ||
puts "Benchmarking....\n" | ||
puts "Size: " + code.bytesize.to_s + " bytes\n" | ||
puts "Iterations: " + num.to_s + "\n" | ||
|
||
__END__ | ||
|
||
$ ruby -rubygems bench.rb 50 | ||
user system total real | ||
albino 0.050000 0.050000 12.830000 ( 13.180806) | ||
pygments::c 1.000000 0.010000 1.010000 ( 1.009348) | ||
pygments::ffi + reload 11.350000 1.240000 12.590000 ( 12.692320) | ||
pygments::ffi 1.130000 0.010000 1.140000 ( 1.171589) | ||
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 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require File.join(File.dirname(__FILE__), '/lib/pygments.rb') | ||
|
||
# Simple marshalling | ||
serialized_lexers = Marshal.dump(Pygments.lexers!) | ||
|
||
# Write to a file | ||
File.open("lexers", 'w') { |file| file.write(serialized_lexers) } | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.