On Mar 12, 2009, at 4:18 PM, William Stein wrote:

>
>> One of the things that drives a lot of my optimizations in Cython has
>> been the maxim that the obvious way should be the fast way, and I
>> especially want to avoid having to resort to tricks to "fool" the
>> compiler to get maximum speed. (Of course in this case we're talking
>> about only a 5% or so difference, assuming no branching). I like the
>
> Are you sure it's a difference of 5%?
>
> I just tried these two programs:
>
> main() {
>     int n = -1, m = 16, k, a=0;
>     for(k=1;k<100000000;k++) {
>       a = n%k + (a<0)?k:0;
>     }
> }
>
> and
>
> main() {
>     int n = -1, m = 16, k, a=0;
>     for(k=1;k<100000000;k++) {
>       a = n%k;
>     }
> }
>
> and the first takes 22% longer than the second.

Thanks for the timings--5% was a conservative estimate, but I didn't  
realize it was that conservative.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to