diff options
author | murphy <murphy@rubychan.de> | 2006-03-21 14:46:34 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2006-03-21 14:46:34 +0000 |
commit | a3b4ad06b992bd418a1d34bfb271c09fd9bedf11 (patch) | |
tree | 722d341f4065b4614b2cfc55cee6ccd3c66fb69a /bench/caching.rb | |
parent | 13255135d7539fd542cf831d6a98f1ba8a5d43ae (diff) | |
download | coderay-a3b4ad06b992bd418a1d34bfb271c09fd9bedf11.tar.gz |
CodeRay::Duo added for cool caching!
bench/caching.rb added t“for demonstrating this.
HTML Encoder: creates unwrapped output by default (still problems with that.)
Numerizing changed (doesn't try to prevent nesting errors)
Speedup: "::String" is faster.
Diffstat (limited to 'bench/caching.rb')
-rw-r--r-- | bench/caching.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/bench/caching.rb b/bench/caching.rb new file mode 100644 index 0000000..3f39fb9 --- /dev/null +++ b/bench/caching.rb @@ -0,0 +1,39 @@ +require 'coderay'
+require 'benchmark'
+
+N = 10
+$code = 'foo(Foo[:foo, /foo/m]); ' * 500
+Benchmark.bm 15 do |bm|
+ bm.report 'loading' do
+ CodeRay::Scanners.load :ruby
+ CodeRay::Encoders.load :div
+ end
+ bm.report 'CodeRay.encode' do N.times do
+ CodeRay.encode($code, :ruby, :div)
+ end end
+ bm.report 'Direct' do N.times do
+ CodeRay::Encoders::Div.new.encode_tokens(
+ CodeRay::Scanners::Ruby.new($code).tokenize
+ )
+ end end
+ bm.report 'Semi-cached' do
+ encoder = CodeRay::Encoders::Div.new
+ N.times do
+ encoder.encode $code, :ruby
+ end
+ end
+ bm.report 'Fully cached' do
+ scanner = CodeRay::Scanners::Ruby.new('')
+ encoder = CodeRay::Encoders::Div.new
+ N.times do
+ scanner.string = $code
+ encoder.encode_tokens scanner.tokens
+ end
+ end
+ bm.report 'Duo cached' do
+ duo = CodeRay::Duo[:ruby, :div]
+ N.times do
+ duo.encode $code
+ end
+ end
+end
|