Skip to content

Commit c99bac0

Browse files
author
Nicolas Laurent
committed
add Array#flatten micro
1 parent ae12c2b commit c99bac0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
array = []
10+
current_array = array
11+
100.times do
12+
next_array = []
13+
current_array.append(0, 1, next_array, 3, 4)
14+
current_array = next_array
15+
end
16+
17+
benchmark 'core-array-flatten-recursive' do
18+
array.flatten
19+
end

bench/micro/array/flatten-simple.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
array = [ [[1, 2], [3,4]], [[5,6], [7,8]] ]
10+
11+
benchmark 'core-array-flatten-simple' do
12+
array.flatten
13+
end

0 commit comments

Comments
 (0)