473,322 Members | 1,379 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.

Anonymus methods in anonymus methods performance

Hi,

I found a way to get result than I want with this anonymus method. But,
it's a little weird to use a anonymus methods in another anonymus
methods. Moreover, i have a performance issue. How can I resolve this ?

Note : NodeList is a List<Nodeand ArcSuccList is a List<Arc>

Node findedNode = this.NodeList.Find(delegate(Node n)
{
if (n.Visited == true)
{ return false; }
else
{
return n.ArcSuccList.TrueForAll(delegate(Arc a)
{
return a.Visited == true;
});
}
});

Thanks,
Steeve

Sep 20 '06 #1
3 1898
"Steeve" <st**********@hotmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
Hi,

I found a way to get result than I want with this anonymus method. But,
it's a little weird to use a anonymus methods in another anonymus
methods. Moreover, i have a performance issue. How can I resolve this ?

Note : NodeList is a List<Nodeand ArcSuccList is a List<Arc>

Node findedNode = this.NodeList.Find(delegate(Node n)
{
if (n.Visited == true)
{ return false; }
else
{
return n.ArcSuccList.TrueForAll(delegate(Arc a)
{
return a.Visited == true;
});
}
});
Why do you think anonymous methods are the source of your performance
problem? Do you find that this code takes considerably longer that the
equivalent code written with nested for loops? There IS a cost associated
with invoking a method via a delegate, but that cost is small. There's
nothing special about anonymous methods that would change that cost unless
the anonymous method has to capture local variables from context. In that
case, each instantiation of the anonymous method will allocate an object on
the GC heap that holds the captured variables. In the code above, there
shouldn't be any captures, so the anonymous method shouldn't have any
unexpected performance overhead.

-cd
Sep 20 '06 #2
Steeve,

You don't say what your performance issue is, or give any kind of
metrics to back this up. What do you think the issue is? The performance
of delegates is better in .NET 2.0 than it was in 1.1 and before, but it is
not as fast as direct method calls.

Here though, the problem is looping within another loop (the Find method
performs a loop action, as does TrueForAll). You should probably use
another method to find your nodes, perhaps indexing them in a way, using a
dictionary (to find based on your condition).

Hope this helps.

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

"Steeve" <st**********@hotmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
Hi,

I found a way to get result than I want with this anonymus method. But,
it's a little weird to use a anonymus methods in another anonymus
methods. Moreover, i have a performance issue. How can I resolve this ?

Note : NodeList is a List<Nodeand ArcSuccList is a List<Arc>

Node findedNode = this.NodeList.Find(delegate(Node n)
{
if (n.Visited == true)
{ return false; }
else
{
return n.ArcSuccList.TrueForAll(delegate(Arc a)
{
return a.Visited == true;
});
}
});

Thanks,
Steeve

Sep 21 '06 #3
It is only a small issue normally which is probably unnoticable but in a loop
within a loop it might add up to something. The line:
return a.Visited == true;
could be
return a.Visited;
this would avoid calling the function to compare the two booleans and would
just return same answer.

The optimizer may even sort this out for you.

Ciaran O'Donnell

"Steeve" wrote:
Hi,

I found a way to get result than I want with this anonymus method. But,
it's a little weird to use a anonymus methods in another anonymus
methods. Moreover, i have a performance issue. How can I resolve this ?

Note : NodeList is a List<Nodeand ArcSuccList is a List<Arc>

Node findedNode = this.NodeList.Find(delegate(Node n)
{
if (n.Visited == true)
{ return false; }
else
{
return n.ArcSuccList.TrueForAll(delegate(Arc a)
{
return a.Visited == true;
});
}
});

Thanks,
Steeve

Sep 21 '06 #4

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

Similar topics

125
by: Raymond Hettinger | last post by:
I would like to get everyone's thoughts on two new dictionary methods: def count(self, value, qty=1): try: self += qty except KeyError: self = qty def appendlist(self, key, *values): try:
37
by: Kay Schluehr | last post by:
Since George Sakkis proposed a new way of doing list comprehensions http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/ac5023ad18b2835f/d3ff1b81fa70c8a7#d3ff1b81fa70c8a7 ...
12
by: Kay Schluehr | last post by:
Hi all, thanks for Your attention ! I think my proposal was more in mind of Rons modified exec than Pythons lambda. When George proposed his unpacking behavoir for list-comps as a pack of...
4
by: Alex Vinokur | last post by:
Copying files : input to output =============================== C/C++ Performance Tests ======================= Using C/C++ Program Perfometer http://sourceforge.net/projects/cpp-perfometer...
8
by: John Ratliff | last post by:
Can the compiler ever inline a method when there is a pointer to the member used? Thanks, --John Ratliff
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
7
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my...
12
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.