BOO-986: Allow DefaultAttribute to work on parameters without an explicit type by...
[boo.git] / performance / duckoperators.boo
blobcf39c034d7337ee6250ad7ed3984b9f2161e968a
1 import Boo.Lang.Runtime
3 def benchmark(label, method as callable()):
4 start = date.Now
5 for i in range(5000000):
6 method()
7 print "${label}\t", (date.Now-start).TotalSeconds
9 class Item:
10 [property(Name)]
11 public name = ""
13 class ListExtensions:
14 [extension]
15 static def addX(l as List, value):
16 l.Add(value)
18 [extension]
19 static length[l as List]:
20 get:
21 return l.Count
23 benchmark "int*int":
24 a as duck = 3
25 b as duck = 2
26 c = a*b
28 benchmark "static int*int":
29 a = 3
30 b = 2
31 c = a*b
33 benchmark "List*int":
34 a as duck = [1, 2, 3]
35 b as duck = 2
36 c = a*b
38 benchmark "static List*int":
39 a = [1, 2, 3]
40 b = 2
41 c = a*b
43 benchmark "List.Add":
44 b as duck = [1, 2, 3]
45 b.Add(4)
47 RuntimeServices.WithExtensions(ListExtensions):
48 benchmark "extension List.Add":
49 b as duck = [1, 2, 3]
50 b.addX(4)
52 benchmark "static List.Add":
53 b = [1, 2, 3]
54 b.Add(4)
56 benchmark "property":
57 b as duck = []
58 c = b.Count
60 RuntimeServices.WithExtensions(ListExtensions):
61 benchmark "extension property":
62 b as duck = []
63 c = b.length
65 benchmark "static property":
66 b = []
67 c = b.Count
69 benchmark "indexer":
70 b as duck = [1]
71 c = b[0]
73 benchmark "static indexer":
74 b = [1]
75 c = b[0]
77 benchmark "set field":
78 (Item() as duck).name = "foo"
80 benchmark "static set field":
81 Item().name = "foo"
83 benchmark "set property":
84 (Item() as duck).name = "foo"
86 benchmark "static set property":
87 Item().name = "foo"