Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ruby Kernel.Array vs Array#wrap
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
$ cat benchmark.yml
prelude: |
require 'active_support/core_ext/array/wrap'
a = nil
Kernel#Array(nil): Array(a)
Array#wrap(nil): Array.wrap(a)
$ benchmark-driver benchmark.yml
Warming up --------------------------------------
Kernel#Array(nil) 4.099M i/s - 4.196M times in 1.023699s (243.94ns/i)
Array#wrap(nil) 8.618M i/s - 8.631M times in 1.001478s (116.04ns/i)
Calculating -------------------------------------
Kernel#Array(nil) 2.772M i/s - 12.298M times in 4.436573s (360.75ns/i)
Array#wrap(nil) 12.954M i/s - 25.854M times in 1.995865s (77.20ns/i)
Array#wrap(nil): 12953905.7 i/s
Kernel#Array(nil): 2771967.5 i/s - 4.67x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.