Am 16.02.2012 00:55, schrieb Kevin Hunter:
Further, the former is faster:

*In [11]: %timeit a.is_Relational*
*10000000 loops, best of 3: 76.3 ns per loop*
*
*
*In [12]: %timeit isinstance(a, Relational)*
*1000000 loops, best of 3: 289 ns per loop*

Microbenchmark results are, in themselves, meaningless. For example, measuring something that takes up negligible amounts of time in any real application isn't worth optimizing and hence not measuring.

Sometimes they are even wrong. You might be measuring loop setup time, and if the interpreter is doing different things depending on whether you're using is_Class or isinstance, you'll get bogus results that won't replicate in real-life applications. (For example, the interpreter might optimize one kind of loop but not the other. Or it might grok that the loop has no effect and optimize it out, and what you're measuring is how long it took the interpreter to realize it. Or a gazillion of other things - unless you know *exactly* what the interpreter is doing, you'll be limited to guesswork, which means you can't rely on any conclusions.)

In this case, you're comparing apples and oranges. is_Relational is checking something different than isinstance (and Ronan says is_Relational is checking the wrong thing). In other words, the difference would be meaningless even if the measurement were accurate.

Just my 2c.

--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to