![]() |
|
Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^2: Getting the size of the call stack (efficiently)by DrWhy (Chaplain) |
on Feb 28, 2007 at 01:27 UTC ( [id://602430]=note: print w/replies, xml ) | Need Help?? |
Apart from that, I'm not surprised you find your code as shown to be slow... it has an infinite loop! You should recast it as something like: ...Um. No? I've played around with my implementation a couple of different ways. I've not yet encountered it failing to terminate with the desired result. update: I didn't realise at first that you only cared about the depth, not what's at each level. In which case, the following snippet will be pretty efficient (since it is blockless):Ah, yeah that's a little faster, about 15% faster than the version with the block. By the way, in benchmarking these two methods I found that getting the stack depth (either way) is really quite fast, I had to do a million repetitions of my test code (each run had a stack depth of 3). That's much less overhead than my naive expectations would have predicted. Update: I played around with the two versions a little more and found that really the difference between the block and the inline versions is only about 4%. My block implementation had some extra overhead unrelated to the 'blockiness' of it. --DrWhy "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."
In Section
Seekers of Perl Wisdom
|
|