Making Samples executable. #!/usr/bin/env io and chmod a+x *.io
[io/quag.git] / samples / speed / speed.io
blobfc2a4525cf1394bf5776a4d7281779fb191e3980
1 #!/usr/bin/env io
4 oneMillion := 1000000
6 results := List clone
8 Tester := Object clone do(
9 foo := method(1)
11 beginTimer := method(
12 self t1 := Date clone now
15 endTimer := method(s,
16 mps := 1 / Date clone now secondsSince(t1)
17 //write(t1 asString, " -> ", Date clone now asString , "\n")
19 write("Io ", s, " := ", mps asString(0,2) , "\n")
22 testSlot := method(
23 beginTimer
24 self x := 1
25 (oneMillion/8) repeat(
26 x; x; x; x;
27 x; x; x; x;
29 endTimer("slotAccesses ")
32 // t := method(x := 1; loop(x = 1)); t
34 testSetSlot := method(
35 beginTimer
36 self x := 1
37 updateSlot := getSlot("updateSlot")
38 (oneMillion/8) repeat(
39 x = 1; x = 1; x = 1; x = 1;
40 x = 1; x = 1; x = 1; x = 1;
42 endTimer("slotSets ")
45 testBlock := method(
46 beginTimer
47 (oneMillion/8) repeat(
48 foo; foo; foo; foo;
49 foo; foo; foo; foo;
51 endTimer("blockActivations ")
54 testInstantiations := method(
55 beginTimer
56 (oneMillion/8) repeat(
57 Tester clone; Tester clone; Tester clone; Tester clone;
58 Tester clone; Tester clone; Tester clone; Tester clone;
60 endTimer("instantiations ")
63 testLocals := method(
64 beginTimer
65 v := 1
66 (oneMillion/8) repeat(
67 v; v; v; v;
68 v; v; v; v;
70 endTimer("localAccesses ")
73 testSetLocals := method(
74 beginTimer
75 //updateSlot := getSlot("updateSlot")
76 v := "1"
77 (oneMillion/8) repeat(
78 v = 1; v = 2; v = 3; v = 4;
79 v = 1; v = 2; v = 3; v = 4;
82 (oneMillion/8) repeat(
83 v = 1; v = 2; v = 3; v = 4;
84 v = 1; v = 2; v = 3; v = 4;
87 endTimer("localSets ")
90 testCFunc := method(
91 beginTimer
92 v := self getSlot("thisContext")
93 (oneMillion/8) repeat(
94 v; v; v; v;
95 v; v; v; v;
97 endTimer("cfuncActivations ")
100 test := method(
101 write("\n")
102 testLocals
103 testSetLocals
104 write("\n")
105 testSlot
106 testSetSlot
107 write("\n")
108 testBlock
109 testInstantiations
110 testCFunc
111 write("Io version := ", System version)
112 write("\n")
113 write("// values in millions per second\n")
117 //1000 repeat(Tester testSetLocals)
118 Tester test