File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,28 @@ Comparison:
143
143
&method: 467095.4 i/s - 4.00x slower
144
144
```
145
145
146
+ ##### Function with single Array argument vs splat arguments [ code] ( code/general/array-argument-vs-splat-arguments.rb )
147
+
148
+ ```
149
+ $ ruby -v array-argument-vs-splat-argument.rb
150
+ ruby 2.1.7p400 (2015-08-18 revision 51632) [x86_64-linux-gnu]
151
+ Calculating -------------------------------------
152
+ Function with single Array argument
153
+ 157.231k i/100ms
154
+ Function with splat arguments
155
+ 4.983k i/100ms
156
+ -------------------------------------------------
157
+ Function with single Array argument
158
+ 5.581M (± 2.0%) i/s - 27.987M
159
+ Function with splat arguments
160
+ 54.428k (± 3.3%) i/s - 274.065k
161
+
162
+ Comparison:
163
+ Function with single Array argument: 5580972.6 i/s
164
+ Function with splat arguments: 54427.7 i/s - 102.54x slower
165
+
166
+ ```
167
+
146
168
### Array
147
169
148
170
##### ` Array#bsearch ` vs ` Array#find ` [ code] ( code/array/bsearch-vs-find.rb )
Original file line number Diff line number Diff line change
1
+ require "benchmark/ips"
2
+
3
+ module M
4
+ ITEMS = ( 1 ..10000 ) . to_a . freeze
5
+
6
+ def self . func ( *args )
7
+ end
8
+ end
9
+
10
+ def fast
11
+ M . func ( M ::ITEMS )
12
+ end
13
+
14
+ def slow
15
+ M . func ( *M ::ITEMS )
16
+ end
17
+
18
+ Benchmark . ips do |x |
19
+ x . report ( "Function with single Array argument" ) { fast }
20
+ x . report ( "Function with splat arguments" ) { slow }
21
+ x . compare!
22
+ end
You can’t perform that action at this time.
0 commit comments