Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Grapher: add speed tests

This creates a new directory speed_test with different
implementations that we can use to power the grapher. The current
implementation is somewhat lacking in that we build up the graph
completely at the end. If we can do it while traversing the tree, we
can build and display it earlier. Similarly, if we can leave out the
line calculation but just work with the columns, we save computation at
load time, and can defer the lines to the drawing process. That will
also clear up the problem of not being able to draw some lines.
  • Loading branch information...
commit 061eb7de48526f13306d1108452db77ed54047c1 1 parent 51b0e7b
@pieter authored
View
26 speed_test/README
@@ -0,0 +1,26 @@
+These tests demonstrate 3 different ways to allocate memory for the graph
+viewer.
+
+The methods:
+
+1. global
+ This method allocates a global memory pool that is used by all structs.
+ It is the fastest method and should be easy to clean up. You do have to
+ make sure that any pointers to the memory used by others is cleaned up.
+1. malloc
+ This methods does two mallocs for every iteration. It is slightly slower
+ (2x as slow), but won't require as much unfragmented memory. It is harder
+ to clean up this memory, as it requires an equal amount of free's.
+2. array
+ This method uses NSMutableArray's to store the necessary information. It is
+ by far the slowest (10x slower than global) but will make use of
+ Objective-C's garbage collection. This is the easiest way to go if it isn't
+ too slow. Looping and creating the arrays takes about 2 seconds for 800k
+ iterations. The question is if this significantly slows down the work.
+
+Results:
+
+ global: 0.18 seconds
+ malloc: 0.39 seconds
+ array: 1.90 seconds
+
View
33 speed_test/array.m
@@ -0,0 +1,33 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <xlocale.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <string.h>
+#include <Cocoa/Cocoa.h>
+
+int main() {
+ srandomdev();
+
+ int i = 0; struct list* last;
+ int num = atoi("8000000");
+
+ int size = 1000;
+ int totColumns = 10000;
+ int currentColumn = 0;
+
+ NSMutableArray* array = [NSMutableArray arrayWithCapacity: 100*size];
+
+ for (i = 0; i < num; i++) {
+ int numColumns = i % 5;
+
+ NSMutableArray* arr = [NSMutableArray arrayWithCapacity: numColumns];
+ int j;
+ for (j = 0; j < numColumns; j++)
+ [arr addObject: @"Ha"];
+ [array addObject: arr];
+ }
+
+ [array release];
+ return 0;
+}
View
55 speed_test/global.c
@@ -0,0 +1,55 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <xlocale.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <string.h>
+struct list {
+ void* columns;
+ int numColumns;
+};
+struct hash {
+ char value[40];
+};
+
+int main() {
+ srandomdev();
+
+ int i = 0; struct list* last;
+ int num = atoi("8000000");
+
+ int size = 1000;
+ int totColumns = 10000;
+ int currentColumn = 0;
+
+ /* Initialize initial list of revisions */
+ struct list* revisionList = malloc(size * sizeof(struct list));
+ struct hash* columns = malloc(totColumns * sizeof(struct hash));
+
+ struct hash standardColumn;
+ strcpy(standardColumn.value, "Haha pieter");
+ for (i = 0; i < num; i++) {
+ if (size <= i) {
+ size *= 2;
+ revisionList = realloc(revisionList, size * sizeof(struct list));
+ }
+
+ struct list* a = revisionList + i;
+ a->numColumns = i % 5;
+ if (currentColumn + a->numColumns > totColumns) {
+ totColumns *= 2;
+ printf("Reallocing columns. New total: %i\n", totColumns);
+ columns = realloc(columns, totColumns * sizeof(struct hash));
+ }
+ int j;
+ for (j = 0; j < a->numColumns; j++) {
+ //ccolumns[currentColumn++] = st
+ strncpy(columns[currentColumn++].value, "Haha pieter is cool", 20);
+ }
+ }
+
+ printf("Num value at 3000 is: %i vs %i\n", revisionList[3000].numColumns, (int) (5 * random()));
+ printf("Value of 1000'd column is: %s\n", columns[1000].value);
+ sleep(5);
+ return 0;
+}
View
48 speed_test/malloc.c
@@ -0,0 +1,48 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <xlocale.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <string.h>
+
+struct list {
+ struct hash* columns;
+ int numColumns;
+};
+struct hash {
+ char value[40];
+};
+
+int main() {
+ srandomdev();
+
+ int i = 0; struct list* last;
+ int num = atoi("8000000");
+
+ int size = 1000;
+ /* Initialize initial list of revisions */
+ struct list** revisionList = malloc(size * sizeof(struct list*));
+
+ struct hash standardColumn;
+ strcpy(standardColumn.value, "Haha pieter");
+ for (i = 0; i < num; i++) {
+ if (size <= i) {
+ size *= 2;
+ revisionList = realloc(revisionList, size * sizeof(struct list*));
+ }
+
+ struct list* a = malloc(sizeof(struct list));
+ revisionList[i] = a;
+
+ a->numColumns = i % 5;
+ a->columns = malloc(a->numColumns * sizeof(struct hash));
+ int j;
+ for (j = 0; j < a->numColumns; j++) {
+ //ccolumns[currentColumn++] = st
+ strncpy(a->columns[j].value, "Haha pieter is cool", 20);
+ }
+ }
+
+ printf("Num value at 3000 is: %i vs %i\n", revisionList[3000]->numColumns, (int) (5 * random()));
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.