aboutsummaryrefslogtreecommitdiffstats
path: root/benchmark/bm_so_lists.rb
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-12 23:01:19 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-12 23:01:19 +0000
commitfd81221a8e2c3a8c77599602fe38cd563d86191d (patch)
tree47faf15269b927feb9e4b13fe2d09a51dae4ddfd /benchmark/bm_so_lists.rb
parent1a4b93cf920d0850061ce4b53351b4cdc7d464c7 (diff)
downloadruby-fd81221a8e2c3a8c77599602fe38cd563d86191d.tar.gz
set svn:eol-style
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'benchmark/bm_so_lists.rb')
-rw-r--r--benchmark/bm_so_lists.rb94
1 files changed, 47 insertions, 47 deletions
diff --git a/benchmark/bm_so_lists.rb b/benchmark/bm_so_lists.rb
index 1fcf24bbc6..3652288881 100644
--- a/benchmark/bm_so_lists.rb
+++ b/benchmark/bm_so_lists.rb
@@ -1,47 +1,47 @@
-#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
-
-NUM = 100
-SIZE = 10000
-
-def test_lists()
- # create a list of integers (Li1) from 1 to SIZE
- li1 = (1..SIZE).to_a
- # copy the list to li2 (not by individual items)
- li2 = li1.dup
- # remove each individual item from left side of li2 and
- # append to right side of li3 (preserving order)
- li3 = Array.new
- while (not li2.empty?)
- li3.push(li2.shift)
- end
- # li2 must now be empty
- # remove each individual item from right side of li3 and
- # append to right side of li2 (reversing list)
- while (not li3.empty?)
- li2.push(li3.pop)
- end
- # li3 must now be empty
- # reverse li1 in place
- li1.reverse!
- # check that first item is now SIZE
- if li1[0] != SIZE then
- p "not SIZE"
- 0
- else
- # compare li1 and li2 for equality
- if li1 != li2 then
- return(0)
- else
- # return the length of the list
- li1.length
- end
- end
-end
-
-i = 0
-while i<NUM
- i+=1
- result = test_lists()
-end
-
-result
+#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
+
+NUM = 100
+SIZE = 10000
+
+def test_lists()
+ # create a list of integers (Li1) from 1 to SIZE
+ li1 = (1..SIZE).to_a
+ # copy the list to li2 (not by individual items)
+ li2 = li1.dup
+ # remove each individual item from left side of li2 and
+ # append to right side of li3 (preserving order)
+ li3 = Array.new
+ while (not li2.empty?)
+ li3.push(li2.shift)
+ end
+ # li2 must now be empty
+ # remove each individual item from right side of li3 and
+ # append to right side of li2 (reversing list)
+ while (not li3.empty?)
+ li2.push(li3.pop)
+ end
+ # li3 must now be empty
+ # reverse li1 in place
+ li1.reverse!
+ # check that first item is now SIZE
+ if li1[0] != SIZE then
+ p "not SIZE"
+ 0
+ else
+ # compare li1 and li2 for equality
+ if li1 != li2 then
+ return(0)
+ else
+ # return the length of the list
+ li1.length
+ end
+ end
+end
+
+i = 0
+while i<NUM
+ i+=1
+ result = test_lists()
+end
+
+result