Skip to content

Instantly share code, notes, and snippets.

View methodmissing's full-sized avatar

Lourens Naudé methodmissing

View GitHub Profile
#define ROBJECT_EMBED_LEN_MAX 3
struct RObject {
struct RBasic basic;
union {
struct {
long numiv;
VALUE *ivptr;
struct st_table *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */
} heap;
VALUE ary[ROBJECT_EMBED_LEN_MAX];
class Callback
def initialize(object = nil, method = :call, &b)
@object, @method = object, method
@object ||= b
end
def call(*args)
@object.__send__(@method, *args)
end
end
class RubyCallback
def initialize(object = nil, method = :call, &b)
@object, @method = object, method
@object ||= b
end
def call(*args)
@object.__send__(@method, *args)
end
end
macbook-pros-computer:hwia lourens$ rake bench
(in /Users/lourens/projects/hwia)
ruby bench/bench.rb
warning: Insecure world writable dir /Users/lourens in PATH, mode 040753
Rehearsal ------------------------------------------------------------------------------
StrHash#[:sym] 0.000000 0.000000 0.000000 ( 0.002916)
HashWithIndifferentAccess#[:sym] 0.020000 0.000000 0.020000 ( 0.021839)
StrHash#['str'] 0.010000 0.000000 0.010000 ( 0.012953)
HashWithIndifferentAccess#['str] 0.000000 0.000000 0.000000 ( 0.003804)
StrHash#key?(:sym) 0.000000 0.000000 0.000000 ( 0.002904)
** Hooks for the Interpreter Events
void rb_add_event_hook(rb_event_hook_func_t func, rb_event_t events)
Adds a hook function for the specified interpreter events.
events should be Or'ed value of:
RUBY_EVENT_LINE
RUBY_EVENT_CLASS
RUBY_EVENT_END
methodmissing:hwia lourens$ rake bench
(in /Users/lourens/projects/hwia)
ruby bench/bench.rb
warning: Insecure world writable dir /Users/lourens in PATH, mode 040753
Rehearsal ------------------------------------------------------------------------------
StrHash#[:sym] 0.000000 0.000000 0.000000 ( 0.002867)
HashWithIndifferentAccess#[:sym] 0.020000 0.000000 0.020000 ( 0.021870)
StrHash#['str'] 0.010000 0.000000 0.010000 ( 0.012825)
HashWithIndifferentAccess#['str] 0.000000 0.000000 0.000000 ( 0.003800)
StrHash#key?(:sym) 0.000000 0.000000 0.000000 ( 0.002781)
macbook-pros-computer:hwia lourens$ rake bench
(in /Users/lourens/projects/hwia)
ruby bench/bench.rb
warning: Insecure world writable dir /Users/lourens in PATH, mode 040753
Rehearsal --------------------------------------------------------------------
StrHash#[:sym] 0.000000 0.000000 0.000000 ( 0.002872)
HashWithIndifferentAccess#[:sym] 0.020000 0.000000 0.020000 ( 0.021855)
----------------------------------------------------------- total: 0.020000sec
user system total real
ELAPSED TIME DISTRIBUTION, dtrace
numcmp
value ------------- Distribution ------------- count
2048 | 0
4096 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 19
8192 | 0
st_init_strtable
value ------------- Distribution ------------- count
static int
rb_any_cmp(a, b)
VALUE a, b;
{
VALUE args[2];
if (a == b) return 0;
if (FIXNUM_P(a) && FIXNUM_P(b)) {
return a != b;
}
int
rb_str_hash(str)
VALUE str;
{
register long len = RSTRING(str)->len;
register char *p = RSTRING(str)->ptr;
register int key = 0;
#if defined(HASH_ELFHASH)
register unsigned int g;