How to avoid throwing an exceptions for a built-in function?
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 12 10:42:18 PDT 2017
On Fri, May 12, 2017 at 12:47:04PM +0200, ag0aep6g via Digitalmars-d-learn wrote:
> On 05/12/2017 10:32 AM, k-five wrote:
> > Interesting! I was worried about performance and for that I did not
> > want to use try-catch.
> > So (isNumberic) is a good solution.
> > http://dlang.org/phobos/std_traits.html#isNumeric
>
> If you're doing this for speed, you better be benchmarking. Exceptions
> are slow when they're thrown. But if no exception is being thrown,
> try-catch is probably faster than checking isNumeric beforehand.
Yes, when it comes to performance-related issues, always profile,
profile, profile. (Or benchmark, benchmark, benchmark. Anything that
gives you actual measurements rather than subjective judgment calls.)
Far too often, what we think will perform poorly is actually nowhere
near the real bottleneck in the program, and we end up wasting too much
time "optimizing" something that doesn't even make a noticeable
difference in the end. Whereas, using a profiler early on will help you
zero in on the real bottlenecks, and you could potentially make huge
performance savings with much less effort.
T
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
More information about the Digitalmars-d-learn
mailing list