Skip to content

Instantly share code, notes, and snippets.

View methodmissing's full-sized avatar

Lourens Naudé methodmissing

View GitHub Profile
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)
** 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
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)
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
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
#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];
typedef struct {
VALUE object;
ID method;
} RCallback;
typedef struct {
VALUE object;
ID method;
} RCallback;
#define GetCallbackStruct(obj) (Check_Type(obj, T_DATA), (RCallback*)DATA_PTR(obj))
static void mark_callback(RCallback* cb)
{
rb_gc_mark(cb->object);
}
static void free_callback(RCallback* cb)
{
xfree(cb);
}
static VALUE
callback_alloc( VALUE klass )
{
VALUE cb;
RCallback* cbs;
cb = Data_Make_Struct(klass, RCallback, mark_callback, free_callback, cbs);
cbs->object = Qnil;
cbs->method = 0;
return cb;