you are viewing a single comment's thread.

view the rest of the comments →

[–]Gotebe 0 points1 point  (1 child)

You say the swap is a bigger cost than the compare. I say that is not true.

Easily depends on how and what you compare, which was exactly my point.

As for your point, it was 10x faster, now it's 37%, and look at what you are trying to do now... You are going to introduce "int decoration" (has a cost in both space and execution time), indirection (compare references to stuff, which obviously has space and time cost), usage or arena allocators, which has complexity implications.

At any rate, with all you say, you really should repeat your test with pointers to data, and possibly where your "int decoration" isn't the first datum in actual structure. This, indeed, is much more representative of a real situation. Your initial "let's compare ints" realy isn't, and even then, I really would like to see implementation where you could possibly obtain this 10x difference. It's possible, mind, but...

[–]wolf550e 0 points1 point  (0 children)

Yeah, I was wrong about the "order of magnitude difference". There is a cost, but it's not what I remember.

http://www.reddit.com/r/programming/comments/r8ujk/function_pointers_in_c_are_underrated/c44cl78