Skip to content

Instantly share code, notes, and snippets.

View methodmissing's full-sized avatar

Lourens Naudé methodmissing

View GitHub Profile
module EventMachine
# Provides a simple interface to push items to a number of subscribers. The
# channel will schedule all operations on the main reactor thread for thread
# safe reactor operations.
#
# This provides a convenient way for connections to consume messages from
# long running code in defer, without threading issues.
#
# channel = EM::Channel.new
# sid = channel.subscribe{ |msg| p [:got, msg] }
def test_read_multi_non_blocking
cbs = fixtures( *%w(1.txt 2.txt 3.txt 4.txt) ).map{|f| AIO::CB.new(f) }
assert_equal nil, AIO.lio_listio( *([AIO::NOWAIT].concat(cbs)) )
sleep(1)
assert_equal %w(one two three four), cbs.map{|cb| cb.buf }
end
NODE_NEWLINE
nd_file = "if"
nd_nth = 1
nd_next:
NODE_IF
nd_cond:
NODE_TRUE
nd_body:
NODE_NEWLINE
nd_file = "if"
#include "ruby.h"
#include "node.h"
#include "env.h"
static VALUE rb_f_callsite( VALUE obj )
{
return INT2FIX(ruby_frame->uniq);
}
void
macbook-pros-computer:~ lourens$ jruby as_bench.rb
Rehearsal ----------------------------------------------------------------------------
Hash#faster_diff 0.702000 0.000000 0.702000 ( 0.641000)
Hash#diff 0.225000 0.000000 0.225000 ( 0.225000)
Hash#faster_deep_merge 0.090000 0.000000 0.090000 ( 0.091000)
Hash#deep_merge 0.066000 0.000000 0.066000 ( 0.065000)
FasterHashWithIndifferentAccess#to_hash 0.337000 0.000000 0.337000 ( 0.337000)
HashWithIndifferentAccess#to_hash 0.254000 0.000000 0.254000 ( 0.254000)
Hash#faster_reverse_merge! 0.138000 0.000000 0.138000 ( 0.138000)
Hash#reverse_merge! 0.086000 0.000000 0.086000 ( 0.086000)
require 'benchmark'
class Hash
def diff(h2)
dup.delete_if { |k, v| h2[k] == v }.merge(h2.dup.delete_if { |k, v| has_key?(k) })
end
def faster_diff(h2)
dup.delete_if { |k, v| h2[k] == v }.merge!(h2.dup.delete_if { |k, v| has_key?(k) })
macbook-pros-computer:~ lourens$ ruby as_bench.rb
Rehearsal ----------------------------------------------------------------------------
Hash#faster_diff 0.100000 0.000000 0.100000 ( 0.103207)
Hash#diff 0.120000 0.000000 0.120000 ( 0.118790)
Hash#faster_deep_merge 0.030000 0.000000 0.030000 ( 0.027385)
Hash#deep_merge 0.030000 0.000000 0.030000 ( 0.032819)
FasterHashWithIndifferentAccess#to_hash 0.030000 0.000000 0.030000 ( 0.027202)
HashWithIndifferentAccess#to_hash 0.030000 0.000000 0.030000 ( 0.032386)
Hash#faster_reverse_merge! 0.030000 0.000000 0.030000 ( 0.032605)
Hash#reverse_merge! 0.040000 0.000000 0.040000 ( 0.045057)
macbook-pros-computer:~ lourens$ ruby as_bench.rb
Rehearsal ----------------------------------------------------------------------------
Hash#faster_diff 0.100000 0.000000 0.100000 ( 0.103662)
Hash#diff 0.120000 0.000000 0.120000 ( 0.116199)
Hash#faster_deep_merge 0.020000 0.000000 0.020000 ( 0.027282)
Hash#deep_merge 0.030000 0.000000 0.030000 ( 0.032799)
FasterHashWithIndifferentAccess#to_hash 0.020000 0.000000 0.020000 ( 0.025512)
HashWithIndifferentAccess#to_hash 0.040000 0.000000 0.040000 ( 0.039692)
Hash#faster_reverse_merge! 0.020000 0.000000 0.020000 ( 0.026483)
Hash#reverse_merge! 0.060000 0.000000 0.060000 ( 0.053396)
macbook-pros-computer:callback lourens$ rake bench
(in /Users/lourens/projects/callback)
ruby bench/bench.rb
warning: Insecure world writable dir /Users/lourens in PATH, mode 040753
Rehearsal ---------------------------------------------------------------------------------
Callback{ 'hai' }.call 0.030000 0.000000 0.030000 ( 0.035305)
RubyCallback{ 'hai' }.call 0.060000 0.000000 0.060000 ( 0.063904)
Callback( 'bai', :to_s ).call 0.020000 0.000000 0.020000 ( 0.010352)
RubyCallback( 'bai', :to_s ).call 0.030000 0.000000 0.030000 ( 0.035379)
Callback( 'bai', :gsub ).call( 'b', 'h' ) 0.030000 0.000000 0.030000 ( 0.027821)
macbook-pros-computer:callback lourens$ rake bench
(in /Users/lourens/projects/callback)
/opt/local/ruby19/lib/ruby/gems/1.9.1/gems/rake-0.8.3/lib/rake.rb:992: warning: Insecure world writable dir /Users/lourens in PATH, mode 040753
Rehearsal ---------------------------------------------------------------------------------
Callback{ 'hai' }.call 0.010000 0.000000 0.010000 ( 0.018309)
RubyCallback{ 'hai' }.call 0.030000 0.000000 0.030000 ( 0.025148)
Callback( 'bai', :to_s ).call 0.000000 0.000000 0.000000 ( 0.007654)
RubyCallback( 'bai', :to_s ).call 0.020000 0.000000 0.020000 ( 0.014259)
Callback( 'bai', :gsub ).call( 'b', 'h' ) 0.040000 0.000000 0.040000 ( 0.041170)
RubyCallback( 'bai', :gsub ).call( 'b', 'h' ) 0.060000 0.000000 0.060000 ( 0.061157)