|
- Author:
- KeYeR (IP: 89.229.31.36)
- Timestamp:
- 04/06/08 17:36:55 (16 years ago)
- Comment:
--
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GCBenchmark
v1 |
v2 |
|
3 | 3 | The code and results below are meant to show the performance differences between Tango and Phobos, isolated to the garbage collector. Benchmark is contributed by [http://petermodzelewski.blogspot.com Piotr Modzelewski]. |
---|
4 | 4 | |
---|
5 | | == Tango code == |
---|
| 5 | == Code == |
---|
| 6 | This same code for both: Tango and Phobos test. (No need to import anything, GC is a part of the runtime). |
---|
6 | 7 | |
---|
7 | 8 | {{{ |
---|
8 | 9 | #!d |
---|
9 | | module bench; |
---|
10 | | |
---|
11 | | import tango.io.Stdout; |
---|
12 | | |
---|
13 | | |
---|
14 | 10 | class TreeNode { |
---|
15 | 11 | int item; |
---|
54 | 50 | }}} |
---|
55 | 51 | |
---|
56 | | == Phobos code == |
---|
57 | | |
---|
58 | | {{{ |
---|
59 | | #!d |
---|
60 | | module benchphobos; |
---|
61 | | |
---|
62 | | import std.stdio, std.conv; |
---|
63 | | |
---|
64 | | class TreeNode { |
---|
65 | | int item; |
---|
66 | | TreeNode left, right; |
---|
67 | | |
---|
68 | | this(int item, TreeNode left=null, TreeNode right=null) { |
---|
69 | | this.item = item; |
---|
70 | | this.left = left; |
---|
71 | | this.right = right; |
---|
72 | | } |
---|
73 | | |
---|
74 | | int check() { |
---|
75 | | return left is null ? item : item + left.check - right.check; |
---|
76 | | } |
---|
77 | | } |
---|
78 | | |
---|
79 | | TreeNode makeTree(int item, int depth) { |
---|
80 | | if (depth > 0) |
---|
81 | | return new TreeNode(item, makeTree(2*item-1, depth-1), makeTree(2*item, depth-1)); |
---|
82 | | else |
---|
83 | | return new TreeNode(item); |
---|
84 | | } |
---|
85 | | |
---|
86 | | void main(char[][] args) { |
---|
87 | | const minDepth = 4; |
---|
88 | | int n = 16; |
---|
89 | | int maxDepth = (minDepth + 2) > n ? minDepth + 2 : n; |
---|
90 | | |
---|
91 | | int check = makeTree(0, maxDepth + 1).check; |
---|
92 | | |
---|
93 | | auto longLivedTree = makeTree(0, maxDepth); |
---|
94 | | |
---|
95 | | for (int depth = minDepth; depth <= maxDepth; depth += 2) { |
---|
96 | | int iterations = 1 << (maxDepth - depth + minDepth); |
---|
97 | | check = 0; |
---|
98 | | |
---|
99 | | for (int i = 1; i <= iterations; i++) |
---|
100 | | check += (makeTree(i, depth)).check + (makeTree(-i, depth)).check; |
---|
101 | | |
---|
102 | | } |
---|
103 | | |
---|
104 | | } |
---|
105 | | }}} |
---|
106 | | |
---|
107 | 52 | == Results == |
---|
108 | 53 | |
|
|
|
|
|
Copyright © 2006-2024 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic