Skip to content

Instantly share code, notes, and snippets.

ruby -wIlib bin/coderay bin/coderay -count
1337
@rubychan
rubychan / gist:1104396
Created July 25, 2011 15:31
playing with instance variables
ruby-1.8.7 > @foo = 42
=> 42
ruby-1.8.7 > @foo
=> 42
ruby-1.8.7 > @foo = nil
=> nil
ruby-1.8.7 > @foo
=> nil
ruby-1.8.7 > remove_instance_variable :@foo
=> nil
@rubychan
rubychan / gist:1033549
Created June 18, 2011 22:09
Club-Mate-Alphabet
echo '(0..728).map{|i|(0..5).map{|j|("%06d"%i.to_s(3)*2)[j,6]}.min}.uniq' | ruby -e 'mate = (0...3**6).map { |i| "%06d" % i.to_s(3).to_i }.map { |s| (0..5).map { |j| s[j..-1] + s[0,j] }.min }.uniq; puts gets.chomp.each_byte.map { |b| mate[b] }.unshift(mate[128])'
122222
002021
002201
002121
002121
010102
002211
010111
002022
rbx-2.0.0pre benchmark/search_bench.rb
user system total real
1 0.000217 0.000040 0.000257 (110.951148)
2 0.000106 0.000050 0.000156 ( 84.890900)
4 0.000165 0.000100 0.000265 (434.183999)
8 0.000453 0.000276 0.000729 (440.761576)
@rubychan
rubychan / gist:1020723
Created June 11, 2011 16:25
Benchmarking Regexp multicore performance on Rubinius 2.0.0pre with removed onig_lock
rbx -v
rubinius 2.0.0dev (1.8.7 03ecc4ad yyyy-mm-dd JI) [x86_64-apple-darwin10.7.4]
with patch https://gist.github.com/1020720
String#gsub
time rbx -e 's = "." * 16_000_000; n = 1; c = s.size / n; (0...n).map { |i| Thread.new { s[c * i, c].gsub(".", "-") }}.map(&:join)'
real 0m33.407s
user 0m33.437s
sys 0m0.074s
diff --git a/vm/builtin/regexp.cpp b/vm/builtin/regexp.cpp
index 32031b8..d510f5d 100644
--- a/vm/builtin/regexp.cpp
+++ b/vm/builtin/regexp.cpp
@@ -264,7 +264,7 @@ namespace rubinius {
forced_encoding_ = true;
}
- thread::Mutex::LockGuard lg(state->shared.onig_lock());
+ // thread::Mutex::LockGuard lg(state->shared.onig_lock());
@rubychan
rubychan / gist:1020620
Created June 11, 2011 14:51
Benchmarking String/Regexp/StringScanner multicore performance on Rubinius 2.0.0pre
rbx -v
rubinius 2.0.0dev (1.8.7 03ecc4ad yyyy-mm-dd JI) [x86_64-apple-darwin10.7.4]
String#gsub
time rbx -e 's = "." * 16_000_000; n = 1; c = s.size / n; (0...n).map { |i| Thread.new { s[c * i, c].gsub(/./, "-") }}.map(&:join)'
real 0m32.890s
user 0m32.896s
sys 0m0.098s
@rubychan
rubychan / gist:1007162
Created June 3, 2011 21:00
StringScanner benchmarks on Rubinius
(built from rvm)
> rbx-head run multi-slice
rubinius 1.2.4dev (1.8.7 25a8922d yyyy-mm-dd JI) [x86_64-apple-darwin10.7.4]
user system total real
multi-slice: 4.837239 0.008982 4.846221 ( 9.869563)
Multi-Threaded: 3.0 MB in 5.12s = 0.6 MB/s @ 18 threads
Single-Threaded: 3.0 MB in 4.75s = 0.6 MB/s
(built from rvm)
> rbx-head-nhydra run multi-slice
Benchmarking with CodeRay 0.9.7:
real 0m4.007s
user 0m3.933s
sys 0m0.068s
Benchmarking with latest CodeRay:
real 0m2.090s
user 0m2.056s
Index: lib/coderay/scanners/ruby/patterns.rb
===================================================================
--- lib/coderay/scanners/ruby/patterns.rb (revision 706)
+++ lib/coderay/scanners/ruby/patterns.rb (working copy)
@@ -33,18 +33,7 @@
add(RESERVED_WORDS, :reserved).
add(PREDEFINED_CONSTANTS, :pre_constant)
- if /\w/u === '∑'
- # MRI 1.8.6, 1.8.7