As some of you probably know am I currently adding some ADTs to Pike, among those a sequence. I've been running some speed comparisons between the new sequence and the array regarding indexing and index assignment ( [] and []= ) and found that the array is about twice as fast as the sequence. I found this quite surprising since it use about the same code as the array, it is just a few rows extra, see the code below. Could the speed difference depends on the extra time it takes to find the '[]() lfun for the sequence?
The CMOD-Code
PIKEFUN mixed `[](mixed index) {
simple_array_index_no_free(Pike_sp, THIS->a, index); Pike_sp++; }
PIKEFUN mixed `[]=(mixed index, mixed value) { should_copy(); simple_set_index(THIS->a, index, value); }
The final C-Code
void f_Sequence_cq__backtick_5B_5D(INT32 args) { #line 67 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" struct svalue * index; #line 67 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" if(args != 1) wrong_number_of_args_error("`[]",args,1); #line 67 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" index=Pike_sp+0-1; dmalloc_touch_svalue(Pike_sp+0-1); #line 67 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" {
simple_array_index_no_free(Pike_sp, THIS->a, index); Pike_sp++; }
void f_Sequence_cq__backtick_5B_5D_eq(INT32 args) { #line 89 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" struct svalue * index; #line 89 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" struct svalue * value; #line 89 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" if(args != 2) wrong_number_of_args_error("`[]=",args,2); #line 89 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" index=Pike_sp+0-2; dmalloc_touch_svalue(Pike_sp+0-2); #line 89 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" value=Pike_sp+1-2; dmalloc_touch_svalue(Pike_sp+1-2); #line 89 "/export/spare/pike/home/peta/Pike/7.5/src/post_modules/_ADT/sequence.c mod" { should_copy(); simple_set_index(THIS->a, index, value); }