Mark,
I was curious about how the NodePools simulation would turn out on my iPod Touch 5th Gen (A5 Processor). The mechanism I used to measure time was taken from the Big Nerd Ranch blog post using mach_absolute_time(). I wrapped up a portion of the function in a block:
NodePools option
static void haveFunWithPool (int nodeCount) {
CGFloat time;
NSLog (@"Creating nodes with the node pool");
BWNodePool *__block nodePool =
[[BWNodePool alloc] initWithNodeSize: sizeof(ListNode)
count: (size_t) nodeCount];
ListNode *__block node = NULL, *__block prev = NULL;
time = BNRTimeBlock(^{
for (int i = 0; i < nodeCount; i++) {
node = [nodePool allocNode];
node->someData = i;
// If you wish, you can do some extra work.
// Construct a linked list through the nodes
node->next = prev;
prev = node;
}
});
Malloc() option
static void haveFunWithMalloc (int nodeCount) {
NSLog (@"Creating nodes with malloc");
CGFloat time;
ListNode *__block node = NULL, *__block prev = NULL;
time = BNRTimeBlock(^{
for (int i = 0; i < nodeCount; i++) {
node = malloc (sizeof(ListNode));
node->someData = i;
// If you wish, you can do some extra work.
// Construct a linked list through the nodes
node->next = prev;
prev = node;
}
});
ListNode *head = node;
printf ("execution time for pool mechanism is: %f\n", time);
NSLog (@"Cleaning up");
while (head != NULL) {
ListNode *nukeNode = head;
head = head->next;
free (nukeNode);
}
NSLog (@"Done");
} // haveFunWithMalloc
Measurements are made in seconds ( I had issues on formatting my original table. I wish I could have just posted an excel spreadsheet )
NodePools
10,000,000
1 2.070027
2 2.067547
3 2.068949
4 2.068740
5 2.066972
20,000,000
1 4.142666
2 4.143904
3 4.142059
4 4.143998
5 4.144053
40,000,000
1 8.286292
2 8.286292
3 8.308340
4 8.291889
5 8.288824
Malloc()
10,000,000
4.655414
4.623228
4.625355
4.653988
4.642747
20,000,000
9.529740
9.356182
9.363784
9.321435
9.303545
[edited table]