diff options
Diffstat (limited to 'etc')
-rw-r--r-- | etc/coderay-lib.tmproj | 36 | ||||
-rw-r--r-- | etc/speedup/direct-stream.rb | 90 |
2 files changed, 79 insertions, 47 deletions
diff --git a/etc/coderay-lib.tmproj b/etc/coderay-lib.tmproj index b4d2d6a..354386a 100644 --- a/etc/coderay-lib.tmproj +++ b/etc/coderay-lib.tmproj @@ -3,7 +3,7 @@ <plist version="1.0"> <dict> <key>currentDocument</key> - <string>speedup/direct-stream.rb</string> + <string>../diff</string> <key>documents</key> <array> <dict> @@ -28,13 +28,15 @@ <key>filename</key> <string>../diff</string> <key>lastUsed</key> - <date>2010-04-15T00:18:50Z</date> + <date>2010-04-28T14:08:29Z</date> + <key>selected</key> + <true/> </dict> <dict> <key>filename</key> <string>../Changes.textile</string> <key>lastUsed</key> - <date>2010-04-15T00:12:51Z</date> + <date>2010-04-28T14:06:25Z</date> </dict> <dict> <key>filename</key> @@ -53,8 +55,6 @@ <string>../ftp.yaml</string> </dict> <dict> - <key>expanded</key> - <true/> <key>name</key> <string>etc</string> <key>regexFolderFilter</key> @@ -89,8 +89,6 @@ <string>../rake_helpers</string> </dict> <dict> - <key>expanded</key> - <true/> <key>name</key> <string>rake_tasks</string> <key>regexFolderFilter</key> @@ -116,7 +114,7 @@ <key>filename</key> <string>../test/scanners/coderay_suite.rb</string> <key>lastUsed</key> - <date>2010-04-15T23:26:11Z</date> + <date>2010-04-28T12:38:44Z</date> </dict> <dict> <key>filename</key> @@ -128,46 +126,46 @@ <key>filename</key> <string>../bench/bench.rb</string> <key>lastUsed</key> - <date>2010-04-15T01:40:12Z</date> + <date>2010-04-28T14:04:10Z</date> </dict> </array> <key>fileHierarchyDrawerWidth</key> <integer>213</integer> <key>metaData</key> <dict> - <key>speedup/current.rb</key> + <key>../Changes.textile</key> <dict> <key>caret</key> <dict> <key>column</key> - <integer>38</integer> + <integer>70</integer> <key>line</key> - <integer>115</integer> + <integer>81</integer> </dict> <key>firstVisibleColumn</key> <integer>0</integer> <key>firstVisibleLine</key> - <integer>90</integer> + <integer>5</integer> </dict> - <key>speedup/direct-stream.rb</key> + <key>../diff</key> <dict> <key>caret</key> <dict> <key>column</key> - <integer>27</integer> + <integer>44</integer> <key>line</key> - <integer>150</integer> + <integer>663</integer> </dict> <key>firstVisibleColumn</key> <integer>0</integer> <key>firstVisibleLine</key> - <integer>132</integer> + <integer>642</integer> </dict> </dict> <key>openDocuments</key> <array> - <string>speedup/current.rb</string> - <string>speedup/direct-stream.rb</string> + <string>../diff</string> + <string>../Changes.textile</string> </array> <key>showFileHierarchyDrawer</key> <true/> diff --git a/etc/speedup/direct-stream.rb b/etc/speedup/direct-stream.rb index 3c15511..dc6984d 100644 --- a/etc/speedup/direct-stream.rb +++ b/etc/speedup/direct-stream.rb @@ -1,5 +1,6 @@ require 'strscan' require 'benchmark' +require 'thread' class Scanner < StringScanner @@ -29,9 +30,9 @@ protected elsif matched = scan(/[,.]/) encoder.text_token matched, :op elsif scan(/\(/) - encoder.open :par + encoder.begin_group :par elsif scan(/\)/) - encoder.close :par + encoder.end_group :par else raise end @@ -45,8 +46,20 @@ class Tokens < Array alias token push alias text_token push alias block_token push - def open kind; push :open, kind end - def close kind; push :close, kind end + def begin_group kind; push :begin_group, kind end + def end_group kind; push :end_group, kind end +end + +class TokensQueue < Queue + def text_token text, kind + push [text, kind] + end + def begin_group kind + push [:begin_group, kind] + end + def end_group kind + push [:end_group, kind] + end end @@ -76,6 +89,21 @@ class Encoder finish end + def encode_queue scanner + setup + queue = TokensQueue.new + Thread.new do + scanner.tokenize queue + queue << nil # end + end.join + Thread.new do + while value = queue.pop + token(*value) + end + end.join + finish + end + def token content, kind if content.is_a? ::String text_token content, kind @@ -98,21 +126,21 @@ class Encoder def block_token action, kind case action - when :open - open kind - when :close - close kind + when :begin_group + begin_group kind + when :end_group + end_group kind else raise end end - def open kind + def begin_group kind @opened << kind @out << "#{kind}<" end - def close kind + def end_group kind @opened.pop @out << '>' end @@ -127,14 +155,14 @@ protected when ::String text_token content, item content = nil - when :open - open item + when :begin_group + begin_group item content = nil - when :close - close item + when :end_group + end_group item content = nil when ::Symbol - block_token content, kind + block_token content, item content = nil else raise @@ -153,22 +181,28 @@ code = " alpha, beta, (gamma).\n" * N scanner = Scanner.new code encoder = Encoder.new -tokens = nil -time_scanning = Benchmark.realtime do - tokens = scanner.tokenize -end -puts 'Scanning: %0.2fs -- %0.0f kTok/s' % [time_scanning, tokens.size / 2 / time_scanning / 1000] +# tokens = nil +# time_scanning = Benchmark.realtime do +# tokens = scanner.tokenize +# end +# puts 'Scanning: %0.2fs -- %0.0f kTok/s' % [time_scanning, tokens.size / 2 / time_scanning / 1000] +# +# time_encoding = Benchmark.realtime do +# encoder.encode_tokens tokens +# end +# puts 'Encoding: %0.2fs -- %0.0f kTok/s' % [time_encoding, tokens.size / 2 / time_encoding / 1000] +# +# time = time_scanning + time_encoding +# puts 'Together: %0.2fs -- %0.0f kTok/s' % [time, tokens.size / 2 / time / 1000] +# scanner.reset -time_encoding = Benchmark.realtime do - encoder.encode_tokens tokens +time = Benchmark.realtime do + encoder.encode_stream scanner end -puts 'Encoding: %0.2fs -- %0.0f kTok/s' % [time_encoding, tokens.size / 2 / time_encoding / 1000] - -time = time_scanning + time_encoding -puts 'Together: %0.2fs -- %0.0f kTok/s' % [time, tokens.size / 2 / time / 1000] +puts 'Direct Streaming: %0.2fs -- %0.0f kTok/s' % [time, (N * 11 + 1) / time / 1000] scanner.reset time = Benchmark.realtime do - encoder.encode_stream scanner + encoder.encode_queue scanner end -puts 'Scanning + Encoding: %0.2fs -- %0.0f kTok/s' % [time, (N * 11 + 1) / time / 1000] +puts 'Queue: %0.2fs -- %0.0f kTok/s' % [time, (N * 11 + 1) / time / 1000] |