[Performance] shootout.binarytrees when implemented with gc is 10x slower than C# on .NET 2.0

Dave Dave_member at pathlink.com
Sat Nov 11 20:36:04 PST 2006


Andrey Khropov wrote:
> So the results are (with cmdline parameter = 16):
> 
> C# on .NET 2.0	    				 :  1.902 sec
> DMD 0.173 - malloc(original version)  :  5.189 sec
> C# on Mono 1.1.18				 :  6.630 sec
> DMD 0.173 - full GC 				 : 19.720 sec
> 

How about this (diff of original version)?

--- binarytrees.d       2006-06-02 09:34:38.000000000 -0500
+++ binarytrees_list.d  2006-11-11 21:30:23.000000000 -0600
@@ -41,7 +41,6 @@
      }

      writefln("long lived tree of depth ",maxDepth,"\t check: ",longLivedTree.ItemCheck);
-    TreeNode.DeleteTree(longLivedTree);

      return 0;
  }
@@ -80,6 +79,9 @@
      TreeNode*           left, right;
      int                 item;

+    static TreeNode*    list;
+    TreeNode*           next;
+
      static TreeNode* opCall(int item, TreeNode* left = null, TreeNode* right = null)
      {
          TreeNode* t = new TreeNode;
@@ -91,11 +93,26 @@

      new(uint sz)
      {
-        return malloc(sz);
+        TreeNode* tn;
+        if(list)
+        {
+            tn = list;
+            list = tn.next;
+        }
+        else
+        {
+            tn = cast(TreeNode*)malloc(sz);
+        }
+        return tn;
      }

      delete(void* p)
      {
-        free(p);
+        if(p)
+        {
+            TreeNode* tn = cast(TreeNode*)p;
+            tn.next = list;
+            list = tn;
+        }
      }
  }



More information about the Digitalmars-d mailing list