1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/benchmark
normal 65651b34b1 struct: avoid all O(n) behavior on access
This avoids O(n) on lookups with structs over 10 members.
This also avoids O(n) behavior on all assignments on Struct members.
Members 0..9 still use existing C methods to read in O(1) time

Benchmark results:

vm2_struct_big_aref_hi*	1.305
vm2_struct_big_aref_lo*	1.157
vm2_struct_big_aset*	3.306
vm2_struct_small_aref*	1.015
vm2_struct_small_aset*	3.273

Note: I chose use loading instructions from an array instead of writing
directly to linked-lists in compile.c for ease-of-maintainability.  We
may move the method definitions to prelude.rb-like files in the future.

I have also tested this patch with the following patch to disable
the C ref_func methods and ensured the test suite and rubyspec works

	--- a/struct.c
	+++ b/struct.c
	@@ -209,7 +209,7 @@ setup_struct(VALUE nstr, VALUE members)
		ID id = SYM2ID(ptr_members[i]);
		VALUE off = LONG2NUM(i);

	-	if (i < N_REF_FUNC) {
	+	if (0 && i < N_REF_FUNC) {
		    rb_define_method_id(nstr, id, ref_func[i], 0);
		}
		else {

* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset):
  new methods to generate bytecode for struct.c
  [Feature #10575]
* struct.c (rb_struct_ref, rb_struct_set): remove
  (define_aref_method, define_aset_method): new functions
  (setup_struct): use new functions
* test/ruby/test_struct.rb: add test for struct >10 members
* benchmark/bm_vm2_struct_big_aref_hi.rb: new benchmark
* benchmark/bm_vm2_struct_big_aref_lo.rb: ditto
* benchmark/bm_vm2_struct_big_aset.rb: ditto
* benchmark/bm_vm2_struct_small_aref.rb: ditto
* benchmark/bm_vm2_struct_small_aset.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-09 15:43:49 +00:00
..
gc * benchmark/gc/gcbench.rb: check GC::OPTS availability 2013-12-19 01:49:59 +00:00
other-lang
bm_app_answer.rb * benchmark/bm_app_answer.rb: revert r42990, benchmark scripts should 2013-09-22 10:01:22 +00:00
bm_app_aobench.rb bm_app_aobench.rb: update links [ci skip] 2014-09-16 10:18:53 +00:00
bm_app_erb.rb
bm_app_factorial.rb
bm_app_fib.rb
bm_app_lc_fizzbuzz.rb * benchmark/bm_app_lc_fizzbuzz.rb: should skip output on benchmark. 2014-09-08 07:08:56 +00:00
bm_app_mandelbrot.rb
bm_app_pentomino.rb
bm_app_raise.rb
bm_app_strconcat.rb
bm_app_tak.rb
bm_app_tarai.rb
bm_app_uri.rb
bm_hash_aref_miss.rb st.c: use power-of-two sizes to avoid slow modulo ops 2014-03-22 23:34:21 +00:00
bm_hash_aref_str.rb st.c: use power-of-two sizes to avoid slow modulo ops 2014-03-22 23:34:21 +00:00
bm_hash_aref_sym.rb benchmark/bm_hash_aref_sym*.rb: force static symbols 2014-10-09 03:44:12 +00:00
bm_hash_aref_sym_long.rb benchmark/bm_hash_aref_sym*.rb: force static symbols 2014-10-09 03:44:12 +00:00
bm_hash_flatten.rb * benchmark/bm_hash_flatten.rb: added. r43896 is about 4 times faster 2013-11-28 10:50:41 +00:00
bm_hash_ident_num.rb st.c: use power-of-two sizes to avoid slow modulo ops 2014-03-22 23:34:21 +00:00
bm_hash_ident_obj.rb st.c: use power-of-two sizes to avoid slow modulo ops 2014-03-22 23:34:21 +00:00
bm_hash_ident_str.rb st.c: use power-of-two sizes to avoid slow modulo ops 2014-03-22 23:34:21 +00:00
bm_hash_ident_sym.rb st.c: use power-of-two sizes to avoid slow modulo ops 2014-03-22 23:34:21 +00:00
bm_hash_keys.rb * benchmark/bm_hash_flatten.rb: added. r43896 is about 4 times faster 2013-11-28 10:50:41 +00:00
bm_hash_shift.rb * benchmark/bm_hash_shift.rb: add benchmark for Hash#shift 2013-04-25 05:03:30 +00:00
bm_hash_values.rb * benchmark/bm_hash_flatten.rb: added. r43896 is about 4 times faster 2013-11-28 10:50:41 +00:00
bm_io_file_create.rb
bm_io_file_read.rb
bm_io_file_write.rb
bm_io_select.rb
bm_io_select2.rb
bm_io_select3.rb
bm_loop_for.rb
bm_loop_generator.rb
bm_loop_times.rb
bm_loop_whileloop.rb
bm_loop_whileloop2.rb
bm_securerandom.rb * lib/securerandom.rb: use OpenSSL::BN for performance improvement. 2014-08-08 11:00:47 +00:00
bm_so_ackermann.rb
bm_so_array.rb
bm_so_binary_trees.rb * benchmark/bm_so_binary_trees.rb: disable `puts' method 2013-06-20 07:30:41 +00:00
bm_so_concatenate.rb
bm_so_count_words.rb
bm_so_exception.rb
bm_so_fannkuch.rb
bm_so_fasta.rb
bm_so_k_nucleotide.rb
bm_so_lists.rb
bm_so_mandelbrot.rb
bm_so_matrix.rb
bm_so_meteor_contest.rb * benchmark/bm_so_meteor_contest.rb: [DOC] Fix a few typos 2013-12-28 08:25:28 +00:00
bm_so_nbody.rb
bm_so_nested_loop.rb
bm_so_nsieve.rb
bm_so_nsieve_bits.rb
bm_so_object.rb
bm_so_partial_sums.rb
bm_so_pidigits.rb
bm_so_random.rb
bm_so_reverse_complement.rb
bm_so_sieve.rb
bm_so_spectralnorm.rb
bm_vm1_attr_ivar.rb
bm_vm1_attr_ivar_set.rb
bm_vm1_block.rb
bm_vm1_const.rb
bm_vm1_ensure.rb
bm_vm1_float_simple.rb
bm_vm1_gc_short_lived.rb * properties. 2013-11-06 00:21:05 +00:00
bm_vm1_gc_short_with_complex_long.rb * properties. 2013-11-06 00:21:05 +00:00
bm_vm1_gc_short_with_long.rb * properties. 2013-11-06 00:21:05 +00:00
bm_vm1_gc_short_with_symbol.rb * properties. 2013-11-06 00:21:05 +00:00
bm_vm1_gc_wb_ary.rb * properties. 2013-11-06 00:21:05 +00:00
bm_vm1_gc_wb_obj.rb * properties. 2013-11-06 00:21:05 +00:00
bm_vm1_ivar.rb
bm_vm1_ivar_set.rb
bm_vm1_length.rb
bm_vm1_lvar_init.rb
bm_vm1_lvar_set.rb
bm_vm1_neq.rb
bm_vm1_not.rb
bm_vm1_rescue.rb
bm_vm1_simplereturn.rb
bm_vm1_swap.rb
bm_vm1_yield.rb
bm_vm2_array.rb
bm_vm2_bigarray.rb
bm_vm2_bighash.rb
bm_vm2_case.rb
bm_vm2_defined_method.rb
bm_vm2_dstr.rb
bm_vm2_eval.rb
bm_vm2_method.rb
bm_vm2_method_missing.rb
bm_vm2_method_with_block.rb
bm_vm2_mutex.rb
bm_vm2_newlambda.rb proc.c (rb_proc_alloc): inline and move to vm.c 2014-09-12 20:57:45 +00:00
bm_vm2_poly_method.rb
bm_vm2_poly_method_ov.rb
bm_vm2_proc.rb
bm_vm2_raise1.rb
bm_vm2_raise2.rb
bm_vm2_regexp.rb
bm_vm2_send.rb
bm_vm2_struct_big_aref_hi.rb struct: avoid all O(n) behavior on access 2014-12-09 15:43:49 +00:00
bm_vm2_struct_big_aref_lo.rb struct: avoid all O(n) behavior on access 2014-12-09 15:43:49 +00:00
bm_vm2_struct_big_aset.rb struct: avoid all O(n) behavior on access 2014-12-09 15:43:49 +00:00
bm_vm2_struct_small_aref.rb struct: avoid all O(n) behavior on access 2014-12-09 15:43:49 +00:00
bm_vm2_struct_small_aset.rb struct: avoid all O(n) behavior on access 2014-12-09 15:43:49 +00:00
bm_vm2_super.rb
bm_vm2_unif1.rb
bm_vm2_zsuper.rb
bm_vm3_backtrace.rb
bm_vm3_clearmethodcache.rb
bm_vm3_gc.rb
bm_vm_thread_alive_check1.rb
bm_vm_thread_close.rb vm*: doubly-linked list from ccan to manage vm->living_threads 2014-05-10 23:48:51 +00:00
bm_vm_thread_create_join.rb
bm_vm_thread_mutex1.rb
bm_vm_thread_mutex2.rb
bm_vm_thread_mutex3.rb
bm_vm_thread_pass.rb
bm_vm_thread_pass_flood.rb
bm_vm_thread_pipe.rb
bm_vm_thread_queue.rb * properties. 2013-11-06 00:21:05 +00:00
driver.rb * benchmark/driver.rb: remove debug output and output results into 2014-05-07 03:07:10 +00:00
make_fasta_output.rb
prepare_so_count_words.rb
prepare_so_k_nucleotide.rb * benchmark/prepare_so_k_nucleotide.rb: use require_relative. 2014-07-11 02:13:09 +00:00
prepare_so_reverse_complement.rb * benchmark/prepare_so_k_nucleotide.rb: use require_relative. 2014-07-11 02:13:09 +00:00
report.rb
run.rb
runc.rb
wc.input.base