This file contains hidden or 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
| 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) }) |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| #include "ruby.h" | |
| #include "node.h" | |
| #include "env.h" | |
| static VALUE rb_f_callsite( VALUE obj ) | |
| { | |
| return INT2FIX(ruby_frame->uniq); | |
| } | |
| void |
This file contains hidden or 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
| NODE_NEWLINE | |
| nd_file = "if" | |
| nd_nth = 1 | |
| nd_next: | |
| NODE_IF | |
| nd_cond: | |
| NODE_TRUE | |
| nd_body: | |
| NODE_NEWLINE | |
| nd_file = "if" |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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] } |
This file contains hidden or 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
| VALUE rb_str_buf_new _((long)); | |
| VALUE rb_str_buf_new2 _((const char*)); | |
| VALUE rb_str_buf_append _((VALUE, VALUE)); | |
| VALUE rb_str_buf_cat _((VALUE, const char*, long)); | |
| VALUE rb_str_buf_cat2 _((VALUE, const char*)); |
This file contains hidden or 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
| static void | |
| return_jump(retval) | |
| VALUE retval; | |
| { | |
| struct tag *tt = prot_tag; | |
| int yield = Qfalse; | |
| if (retval == Qundef) retval = Qnil; | |
| while (tt) { | |
| if (tt->tag == PROT_YIELD) { |
This file contains hidden or 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
| static VALUE | |
| rb_f_throw(argc, argv) | |
| int argc; | |
| VALUE *argv; | |
| { | |
| VALUE tag, value; | |
| struct tag *tt = prot_tag; | |
| rb_scan_args(argc, argv, "11", &tag, &value); | |
| tag = ID2SYM(rb_to_id(tag)); |
This file contains hidden or 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
| static inline VALUE | |
| call_cfunc(func, recv, len, argc, argv) | |
| VALUE (*func)(); | |
| VALUE recv; | |
| int len, argc; | |
| VALUE *argv; | |
| { | |
| if (len >= 0 && argc != len) { | |
| rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", | |
| argc, len); |