473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

optimisation issue

Hello!

I have a rather large C# Select Case statement and it is going to get
larger.
I think it would be advisable to replace it with a mapping between
strings (the select is on a string) and actions ( functions ) .
In C# we had function pointer that we could use; what is the
correspondent in C#?

We also have performance constraints, so whatever solution you propose
should consider that. (I understand that delegates are VERY slow, or I
could have used them :( ... )

Thank you!

Sep 5 '06 #1
5 1121
Define VERY slow ;-p

Particularly in 2.0, they are much quicker - some benchmarks here:
http://blogs.wdevs.com/jdunlap/archi.../20/10912.aspx

a Dictionary<string, SomeDelegateTypecould be a reasonable lookup
mechanism; alternatively (avoiding delegates) you could keep your
string-based switch statement (which compiles to a dictionary/hashtable
anyway) and move the code from each block out to separate functions - it at
least keeps each function clearly defined.

Any help?

Marc
Sep 5 '06 #2
Hi,

You can use a delegate , this would be the contrapart of the C++ function
pointers.

What makes you think that delegates are slow?
Delegates are the foundation of the events that are so widely used in the
framework.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<sb*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Hello!

I have a rather large C# Select Case statement and it is going to get
larger.
I think it would be advisable to replace it with a mapping between
strings (the select is on a string) and actions ( functions ) .
In C# we had function pointer that we could use; what is the
correspondent in C#?

We also have performance constraints, so whatever solution you propose
should consider that. (I understand that delegates are VERY slow, or I
could have used them :( ... )

Thank you!

Sep 5 '06 #3

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

You can use a delegate , this would be the contrapart of the C++ function
pointers.

What makes you think that delegates are slow?
http://www.jelovic.com/weblog/e133.htm

Check out the MSDN article linked from there....
Delegates are the foundation of the events that are so widely used in the
framework.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Tanx alot for your help, using delegates sometimes increases my runtime
by +100%, but it is still in the accepted margins.

Thanx alot, guys!

Sep 5 '06 #4
I would recommend using an interface, and having classes implement that
interface. That's going to get you the best performance, compared to
delegates (while they are faster in 2.0, they are not going to be faster
than interface implementations).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<sb*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Hello!

I have a rather large C# Select Case statement and it is going to get
larger.
I think it would be advisable to replace it with a mapping between
strings (the select is on a string) and actions ( functions ) .
In C# we had function pointer that we could use; what is the
correspondent in C#?

We also have performance constraints, so whatever solution you propose
should consider that. (I understand that delegates are VERY slow, or I
could have used them :( ... )

Thank you!

Sep 5 '06 #5
That is dated June 2003, so I'm guessing 1.1;

They did a *lot* of work speeding this up in 2.0 - I don't think you can
hold these figures to ransom. In either case, the best thing is to (as you
have) try it, and see what impact it has for realistic usage in your app -
and make sure you use 2.0 ;-p

Marc
Sep 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon Elliott | last post by:
What optimisation do compilers typically provide when passing STL containers around? For example, if I do something like this: struct Tbloggs { std::string s1; }; typedef...
16
by: simonwittber | last post by:
Hello People. I've have a very tight inner loop (in a game app, so every millisecond counts) which I have optimised below: def loop(self): self_pool = self.pool self_call_exit_funcs =...
13
by: David Mitchell | last post by:
I use the above function in queries for a number of forms and reports. The reports take approx 20 seconds to open. There are only 100 product id's in tblProducts. My concern is that the time will...
17
by: EC-AKD | last post by:
Hi All, I am new to the concept of optimising codes in C. I was wondering if C level inlining of code is any way comparable to macros. I believe that inlining is equivalent to writing macros....
1
by: Rahul Iyer | last post by:
G'day I have encountered quite a strange problem with a new function i've added to an existing software. Pseudo code of actions. -- begins -- func_foo (){
8
by: Jon Maz | last post by:
Hi, I'm facing a code-optimisation issue on an asp.net/vb.net/SQL Server 2000 project. A web page containing not much more than 3 DropDownLists is taking nigh on 6 seconds to load, because each...
1
by: David Welch | last post by:
Hi, I have a bit of code where I am relying on empty base member optimisation. The bit of code is below: template<typename Enum> struct EncodePrefix { template<Enum e> struct Apply
1
by: grid | last post by:
Hi, I was exploring the affect of cache on program performance/optimisation.Is it the compilers responsibility only to consider this kind of optimisation or the programmer can do his bit in this...
3
by: Jeff | last post by:
Hello Sorry if this isn't entirely a C language question - perhaps someone could suggest a more appropriate group? I'm running the appended code on a Mips R12000 processor and am getting very...
2
by: special_dragonfly | last post by:
Hello, I know this might be a little cheeky, and if it is, please say, but I need a little hand optimising some code. For the simple reason that this is 'company' code and I have no idea what I'm...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.