From: Kero van Gelder Date: 2002-12-20T08:39:57+09:00 Subject: speed differences between ruby versions --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello all, In search of a bug, I created some sample code for a C-binding. (Code attached, mkdir test/; cd test/; ruby extconf.rb; make; cd ..; ruby test/buggy.rb) Turns out, @home (measured with `time ruby test/buggy.rb`): 1.6.5, 1.6.8, 1.7.2 (date unknown) are fast 1.6.7 slowish (10x) 1.7.3 (dec 19) slow (>30x) and @work: 1.6.7 (I think), 1.7.2 (date unknown) fast 1.7.3 (dec 16) slow It is all very consistent on one machine, but I can not pinpoint what causes it... Anyone can reproduce this? Any insights? `ruby -rprofile` shows the difference in speed as follows (i.e. Bla#new): fast: % cumulative self self total time seconds seconds calls ms/call ms/call name 55.97 1.36 1.36 12345 0.11 0.11 Bla#new 43.62 2.42 1.06 1 1060.00 2420.00 Fixnum#times 0.00 2.42 0.00 1 0.00 0.00 Class#inherited 0.00 2.42 0.00 1 0.00 0.00 Array#allocate 0.00 2.42 0.00 12 0.00 0.00 String#allocate 0.00 2.42 0.00 1 0.00 2430.00 #toplevel 0.00 2.42 0.00 1 0.00 0.00 Kernel.require slow: % cumulative self self total time seconds seconds calls ms/call ms/call name 95.09 38.34 38.34 12345 3.11 3.11 Bla#new 4.91 40.32 1.98 1 1980.00 40320.00 Integer#times 0.00 40.32 0.00 1 0.00 0.00 Array#allocate 0.00 40.32 0.00 1 0.00 40320.00 #toplevel 0.00 40.32 0.00 1 0.00 0.00 Class#inherited 0.00 40.32 0.00 4 0.00 0.00 String#allocate 0.00 40.32 0.00 1 0.00 0.00 Kernel.require Bye, Kero. PS: my bug turned out to be "-ldmalloc" for gcc, that solved my memory leak, but not the speed difference. +--- Kero ------------------------------ kero@chello.nl ---+ | Don't split your mentality without thinking twice | | Proud like a God -- Guano Apes | +--- M38c ---------- http://httpd.chello.nl/k.vangelder ---+ --y0ulUmNC+osPPQO6 Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="native.c" #include VALUE rb_cBla; typedef struct Bla { char str[123456]; } Bla; void bla_free(Bla *bla) { free(bla); // fprintf(stderr, "#"); } VALUE bla_new() { VALUE info; Bla *one = ALLOC(Bla); info = Data_Wrap_Struct(rb_cBla, 0, bla_free, one); // rb_obj_call_init(info, 0, 0); return info; } void Init_native(void) { rb_cBla = rb_define_class("Bla", rb_cObject); rb_define_module_function(rb_cBla, "new", bla_new, 0); } --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="buggy.rb" require 'test/native' 12345.times { Bla.new() } --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="extconf.rb" require 'mkmf' create_makefile("native") --y0ulUmNC+osPPQO6--