Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Good day all,

I have an ecumenical question on effeciency.

Consider a function to check if a specific value exists on a table.

Currently each table has its own, overloaded by key type.

But there will be a number of very similar fuctions in the final system.

So that makes them ideal candidates for a single template function in a shared library.

Or a single conventional check function:

check(String^ ArgTable, String^ ArgKeyName, Object^ ArgKeyValue)


ArgKeyValue is subesequently interrogated to determine its type.

This third option looks like the cleanest in terms of readabilty and fewest lines of code,while the first generated the most code by some distance.

But which solution will perform best at run time?
Posted
Updated 5-Apr-11 9:46am
v4

The second one, in my opinion.

Ger Hayden wrote:
This third option looks like the cleanest in terms of readabilty and fewest lines of code

I don't think so (just think about the 'great switch' on ArgKeyValue).

:-)
 
Share this answer
 
Comments
Ger Hayden 5-Apr-11 15:34pm    
No - It will ever only be int or String^
Ger
Ger Hayden 5-Apr-11 15:42pm    
I have just updated the key request in the question, bearing in mind that ArgKey value will only be a six line if-else construct.
CPallini 5-Apr-11 16:30pm    
At glance, I would say solutions (1) and (2) are equivalent and both perform better than (3). Anyway I would care more about code neatness than performance gain.
Not only your options are not explained properly; but it is clear that the question is incorrect. The term "best" suggests that the relationship of (partial) ordering is defined on the set of option. No, you don't define it. Your question looks like: the car A has better fuel economy, but the car B has higher clearance. Which one is the best?

—SA
 
Share this answer
 
Comments
Ger Hayden 5-Apr-11 15:40pm    
Apologies if the english is not Oxford Standard, but your interpretation is not far off the mark. A small code footprint is attractive, but if it is going to run more slowly than any other option then it is off the table.
Sergey Alexandrovich Kryukov 5-Apr-11 16:04pm    
It has nothing to do with English (which is not my native :-)
I agree of course with the idea of the critical requirement (this is all you note really about).
I only say you did not clearly describe the options. Like #1 is ..., #2 is....
I fail to understand what are they, really.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900