On Tuesday, September 9, 2014 5:48:59 AM UTC-7, Volker Braun wrote:
>
> But that doesn't work at the C level, you either compile something in or 
> not. So you can't apply it to the (presumably) speed-critical c(p)def 
> functions, only to plain Python functions
>
True 

> where overhead wasn't much of an issue to start with.
>
 
Don't  underestimate the importance of "reasonable" performance at python 
level. In for instance magma, the first version of a program often has 
"decent" performance (at least in my experience), where "decent" means: I 
can easily do an example in the range of interest. In sage, I have never 
had that. You can use cython to get *great* performance, but at the expense 
of putting in significant work (unwrapping all the convenient sage-layers 
of things, making sure you avoid category overhead, etc). I think it's 
important to have decent performance from the get-go, because that often 
means you don't have to bother putting in 5 extra days of optimizing code 
to do the example you're interested in. 

I'm not sure whether the tests involved with this would lead to a 
significant slow-down, but these things add up. With profiling sage code, I 
have often noticed that there's not a single bottleneck. It's just "death 
by thousand cuts". It seems to me this might add another cut at python 
level. In python, looking up a global flag is going to be relatively slow, 
because, if addressed by its proper name, it involves checking several 
__dict__s. This adds noticeably to the overhead:

sage.misc.sageinspect.cite_enabled = False #just borrowing some spot
def citetest(a): pass
sage.misc.sageinspect.citetest = citetest #to compare symbol lookup with 
call overhead

def t1(a):
    if sage.misc.sageinspect.cite_enabled:
        print "cite"
    return 2*a

def t2(a):
    return 2*a
    
def t3(a):
    sage.misc.sageinspect.citetest("citation")
    return 2*a   

sage: %timeit t1(20)
1000000 loops, best of 3: 675 ns per loop
sage: %timeit t2(20)
1000000 loops, best of 3: 396 ns per loop
sage: %timeit t3(20)
1000000 loops, best of 3: 797 ns per loop

Unlike a "cdef cite_enabled" flag on cython level, testing the flag on 
python level is quite noticeable. I'd suspect that cythonizing the process 
would still be comparable, due to the symbol lookup required for finding 
the cythonized routine.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to