Skip to content

Instantly share code, notes, and snippets.

@sonots
Created September 20, 2017 08:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sonots/086074b0b53e9cbf78040d03a7ec7be1 to your computer and use it in GitHub Desktop.
string interpolation performance 2.4.1 vs trunk (2.5.0dev)
b = 'b'
1_000_000.times { "a#{b}c" }
@sonots
Copy link
Author

sonots commented Sep 20, 2017

$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
$ ruby --dump=insns -e 'b = "b"; "a#{b}c"'
== disasm: #<ISeq:<main>@-e>============================================
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] b
0000 trace            1                                               (   1)
0002 putstring        "b"
0004 setlocal_OP__WC__0 3
0006 putobject        "a"
0008 getlocal_OP__WC__0 3
0010 tostring
0011 putobject        "c"
0013 concatstrings    3
0015 leave
$ /usr/bin/time ruby /tmp/bm_string_interpolation.rb
        0.28 real         0.21 user         0.02 sys
$ ./ruby -v
ruby 2.5.0dev (2017-09-20 help_dump 59972) [x86_64-darwin16]
last_commit=ruby.c: show help messages of --dump
$ ./ruby --dump=insns -e 'b = "b"; "a#{b}c"'
== disasm: #<ISeq:<main>@-e>============================================
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] b
0000 trace            1                                               (   1)
0002 putstring        "b"
0004 setlocal_OP__WC__0 3
0006 putobject        "a"
0008 getlocal_OP__WC__0 3
0010 dup
0011 branchiftype     5, 19
0014 dup
0015 opt_send_without_block <callinfo!mid:to_s, argc:0, FCALL|ARGS_SIMPLE>, <callcache>
0018 tostring
0019 putobject        "c"
0021 concatstrings    3
0023 leave
$ /usr/bin/time ./ruby benchmark/bm_string_interpolation.rb
        0.20 real         0.19 user         0.00 sys

@sonots
Copy link
Author

sonots commented Sep 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment