source: EcnlProtoTool/trunk/mruby-1.2.0/benchmark/bm_so_lists.rb@ 321

Last change on this file since 321 was 321, checked in by coas-nagasima, 7 years ago

文字コードを設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 1001 bytes
Line 
1#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
2
3NUM = 300
4SIZE = 10000
5
6def test_lists()
7 # create a list of integers (Li1) from 1 to SIZE
8 li1 = (1..SIZE).to_a
9 # copy the list to li2 (not by individual items)
10 li2 = li1.dup
11 # remove each individual item from left side of li2 and
12 # append to right side of li3 (preserving order)
13 li3 = Array.new
14 while (not li2.empty?)
15 li3.push(li2.shift)
16 end
17 # li2 must now be empty
18 # remove each individual item from right side of li3 and
19 # append to right side of li2 (reversing list)
20 while (not li3.empty?)
21 li2.push(li3.pop)
22 end
23 # li3 must now be empty
24 # reverse li1 in place
25 li1.reverse!
26 # check that first item is now SIZE
27 if li1[0] != SIZE then
28 p "not SIZE"
29 0
30 else
31 # compare li1 and li2 for equality
32 if li1 != li2 then
33 return(0)
34 else
35 # return the length of the list
36 li1.length
37 end
38 end
39end
40
41i = 0
42while i<NUM
43 i += 1
44 result = test_lists()
45end
46
47result
Note: See TracBrowser for help on using the repository browser.