[llvm-commits] [test-suite] r117713 - in /test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort: benchmark.c sort.c sort.h

Andrew Trick atrick at apple.com
Fri Oct 29 14:20:57 PDT 2010


Author: atrick
Date: Fri Oct 29 16:20:57 2010
New Revision: 117713

URL: http://llvm.org/viewvc/llvm-project?rev=117713&view=rev
Log:
This benchmark was chosen somewhat at random to see if we can make the
results more predictable on certain platforms. We can do a little
better by reusing malloc'd memory. This change in effect converts it
from a malloc benchmark to a malloc/free benchmark.

Modified:
    test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/benchmark.c
    test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.c
    test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.h

Modified: test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/benchmark.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/benchmark.c?rev=117713&r1=117712&r2=117713&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/benchmark.c (original)
+++ test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/benchmark.c Fri Oct 29 16:20:57 2010
@@ -48,9 +48,11 @@
   LinkList *ll; /* ll = lINKED lIST */
   List *l;      /* l = lIST */
   /* Andrew Trick: added "repeat" to measure performance, not just correctness.
-   * This also required adding origList. */
-  int repeat = 0;
+   * Also added FreeLinkList and removed leaks.
+   * This required adding origList and origLinkList. */
+  LinkList *origLinkList;
   int *origList;
+  int repeat = 0;
   if (argc > 1) {
     repeat = strtol(argv[1], 0, 0);
   }
@@ -59,6 +61,7 @@
   struct timeval t, tt;
 #endif
   while ((err = ReadList(&ll, &l)) == 0) {
+    origLinkList = ll;
     origList = l->l;
     l->l = (int*) malloc(sizeof(int)*l->n);
     memcpy(l->l, origList, sizeof(int)*l->n);
@@ -68,7 +71,9 @@
     for (; repeat > 0; --repeat) {
       l = BubbleSort(l, LessThan);
       memcpy(l->l, origList, sizeof(int)*l->n);
-      ll = QuickSort(ll, LessThan);
+      /* QuickSort returns a new list, and origLinkList is unmodified */
+      ll = QuickSort(origLinkList, LessThan);
+      FreeLinkList(ll);
     }
 #ifdef TIMEREPEAT
     gettimeofday(&tt,0);
@@ -80,9 +85,14 @@
     l = BubbleSort(l, LessThan);
     PrintList(l);
     printf("\nQuickSort:  "); fflush(stdout);
-    ll = QuickSort(ll, LessThan);
+    ll = QuickSort(origLinkList, LessThan);
     PrintLinkList(ll);
     printf("\n");
+    FreeLinkList(ll);
+    FreeLinkList(origLinkList);
+    free(l->l);
+    free(l);
+    free(origList);
     listno++;
   }
 

Modified: test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.c?rev=117713&r1=117712&r2=117713&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.c (original)
+++ test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.c Fri Oct 29 16:20:57 2010
@@ -57,7 +57,8 @@
   if (l==NULL) return(NULL);
   else
     {
-      FirstElement=l;
+      FirstElement=(LinkList*) malloc(sizeof(LinkList));
+      *FirstElement=*l;
       /* Build the Inf- and the SupList */
       for (p=l->next; p!=NULL; p=p->next)
 	{
@@ -79,10 +80,12 @@
 	    }
 	}
       /* Sort Inf- and SupList by means of recursion */ 
-      InfList=QuickSort(InfList, compare);
-      SupList=QuickSort(SupList, compare);
+      SortList=QuickSort(SupList, compare);
+      FreeLinkList(SupList);
+      SupList = SortList;
+      SortList=QuickSort(InfList, compare);
+      FreeLinkList(InfList);
       /* Join Lists to form quicksorted list */
-      SortList=InfList;
       if (SortList!=NULL)
 	{
 	  /* Fast forward to the end of SortList */
@@ -120,4 +123,11 @@
     }
 }
 
-
+void FreeLinkList(LinkList *l)
+{
+  LinkList* next;
+  for (; l!=NULL; l=next) {
+    next = l->next;
+    free(l);
+  }
+}

Modified: test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.h?rev=117713&r1=117712&r2=117713&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.h (original)
+++ test-suite/trunk/MultiSource/Benchmarks/McCat/01-qbsort/sort.h Fri Oct 29 16:20:57 2010
@@ -35,4 +35,5 @@
 LinkList *QuickSort(LinkList *l, BOOL (*compare)(int, int));
 void PrintList(List *l);
 void PrintLinkList(LinkList *l);
+void FreeLinkList(LinkList *l);
 #endif /* ifndef _SORT_H_ */





More information about the llvm-commits mailing list