From: "Mauricio Fernández" Date: 2005-07-22T02:59:12+09:00 Subject: Re: C extension makes things slower On Fri, Jul 22, 2005 at 02:05:56AM +0900, Phil Tomson wrote: > In article <42DF4F1D.2060607@capitain.de>, > Pit Capitain wrote: > >Phil Tomson schrieb: > >> And the results: > >> l% ruby point.rb > >> Total time for pure ruby point test: 8.600752 > >> ACO_Ext initializing... > >> Total time for extension point test: 6.086567 > However, here's the result of another run: > > Total time for pure ruby point test: 8.051388 > ACO_Ext initializing... > Total time for extension point test: 9.212984 You're doing things like static VALUE aco_point_diff(VALUE self, VALUE other){ double self_x = NUM2DBL(rb_iv_get(self, "@x")); double self_y = NUM2DBL(rb_iv_get(self, "@y")); double other_x= NUM2DBL(rb_iv_get(other, "@x")); double other_y= NUM2DBL(rb_iv_get(other, "@y")); double xdiffsq= pow( (self_x - other_x),2 ); double ydiffsq= pow( (self_y - other_y),2 ); return rb_float_new(sqrt( xdiffsq + ydiffsq ) ); } when you probably want something resembling typedef struct { double x; double y; } ACO_Point_Struct; static VALUE aco_point_diff(VALUE self, VALUE other) { ACO_Point_Struct *_self, *_other; double dx, dy; Data_Get_Struct(self, ACO_Point_Struct, _self); Data_Get_Struct(other, ACO_Point_Struct, _other); dx = _self->x - _other->x; dy = _self->y - _other->y; return rb_float_new(sqrt(dx * dx + dy * dy)); } etc -- Mauricio Fernandez