Skip to content

Instantly share code, notes, and snippets.

@cielavenir
Created September 13, 2015 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cielavenir/503bb004ed91307c78c7 to your computer and use it in GitHub Desktop.
Save cielavenir/503bb004ed91307c78c7 to your computer and use it in GitHub Desktop.
ダブルクオートとシングルクオートの速度差は(ほぼ)ない ref: http://qiita.com/cielavenir/items/3bbb4e483df8ba03de03
%q(x=5;puts "aaa #{x**3}")
irb> RubyVM::InstructionSequence.compile(%q(x=5;puts "aaa #{x**3}")).to_a
=> ["YARVInstructionSequence/SimpleDataFormat", 2, 0, 1, {:arg_size=>0, :local_size=>2, :stack_max=>4}, "<compiled>", "<compiled>", nil, 1, :top, [:x], 0, [], [1, [:trace, 1], [:putobject, 5], [:setlocal_OP__WC__0, 2], [:trace, 1], [:putself], [:putobject, "aaa "], [:getlocal_OP__WC__0, 2], [:putobject, 3], [:opt_send_simple, {:mid=>:**, :flag=>256, :orig_argc=>1, :blockptr=>nil}], [:tostring], [:concatstrings, 2], [:opt_send_simple, {:mid=>:puts, :flag=>264, :orig_argc=>1, :blockptr=>nil}], [:leave]]]
irb> RubyVM::InstructionSequence.compile(%q(x=5;puts 'aaa '+(x**3).to_s)).to_a
=> ["YARVInstructionSequence/SimpleDataFormat", 2, 0, 1, {:arg_size=>0, :local_size=>2, :stack_max=>4}, "<compiled>", "<compiled>", nil, 1, :top, [:x], 0, [], [1, [:trace, 1], [:putobject, 5], [:setlocal_OP__WC__0, 2], [:trace, 1], [:putself], [:putstring, "aaa "], [:trace, 1], [:getlocal_OP__WC__0, 2], [:putobject, 3], [:opt_send_simple, {:mid=>:**, :flag=>256, :orig_argc=>1, :blockptr=>nil}], [:opt_send_simple, {:mid=>:to_s, :flag=>256, :orig_argc=>0, :blockptr=>nil}], [:opt_plus, {:mid=>:+, :flag=>256, :orig_argc=>1, :blockptr=>nil}], [:opt_send_simple, {:mid=>:puts, :flag=>264, :orig_argc=>1, :blockptr=>nil}], [:leave]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment