very different execution time
very different execution time
- Subject: very different execution time
- From: Hans van der Meer <email@hidden>
- Date: Fri, 28 Sep 2007 13:52:04 +0200
I have two versions of a class for the production of permutations.
In one the permutation is numbers in an int array, in the other
objects in a NSMutableArray.
There is a huge difference in execution time between these two
versions. When the array version takes 135 seconds, the corresponding
calculation with NSMutableArray takes 700 seconds; using
exchangeObjectAtIndex:withObjectAtIndex: takes even 25% more. Without
the specific array operations the time needed is not much less then
for the array version. I therefore conclude that the replace
operations in NSMutableArray are responsible for the huge difference.
However, given that in the one integers are assigned and in the other
pointers, I have difficulties to understand the magnitude of the
difference. Could it be the object message sending mechanism? Perhaps
I have something wrong? If that difference is real and without cure,
what causes it?
I hope someone will provide the answer.
The operations concerned are in a recursive method of which the core is:
if (steps[level] > 0) { i = --steps[level];
unsigned int tmp = permutation[i];
permutation[i] = permutation[i + 1]; permutation[i + 1] = tmp;
} else if (level > 0) {
unsigned int tmp = permutation[0];
for (i = 0; i < level; i++) { permutation[i] = permutation[i + 1]; }
permutation[level] = tmp;
[self nextlevel: level]; ...
}
and for the Foundation collection:
if (steps[level] > 0) { i = --steps[level];
id temp = [theValues objectAtIndex: i];
[theValues replaceObjectAtIndex: i withObject: [theValues
objectAtIndex: (i + 1)]];
[theValues replaceObjectAtIndex: (i + 1) withObject: temp];
} else if (level > 0) {
id temp = [theValues objectAtIndex: 0];
for (i = 0; i < level; i++) {
[theValues replaceObjectAtIndex: i withObject: [theValues
objectAtIndex: (i + 1)]];
}
[theValues replaceObjectAtIndex: level withObject: temp];
[self nextlevel: level]; ...
}
Hans van der Meer
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden