Csound Csound-dev Csound-tekno Search About

Re: [Cs-dev] which is faster?

Date2006-10-21 22:25
FromVictor Lazzarini
SubjectRe: [Cs-dev] which is faster?
Steven,

Erik's text in www.mega-nerd.com/FPcast explains
it well.

I went and tested the two options I gave here:
lrint() + test is slower than just casting.
lrint() on its own is faster than casting, but
it rounds; if truncation is needed then we're
better off with casting.

I am just checking the best way to make table
lookup code faster. I suppose using integer
sampling increments and indexing is the fastest,
anyway.

Victor

>
> Hi Victor,
>
> This is somewhat related and is a question for everyone:
> in H/sysdep.h, if USE_LRINT is enabled, does the code in
> there:
>
>   230 #    define MYFLT2LONG(x) ((long) lrintf((float)
> (x)))
>
> not yield a different result than:
>
> 263 #    define MYFLT2LONG(x) ((long) (x))
>
> ? I guess I'm wondering what that code is all about.
>
> Thanks!
> steven
>
>
> On 10/21/06, Victor Lazzarini 
> > wrote: A question for any int to float guru out there
> > (Erik?), which of the two truncation codes below would
> be faster? >
> > (1)
> > double a; long b;
> > b = (long) a;
> >
> > (2)
> > double a; long b;
> > b = lrint(a);
> > b = b <= a ? b : b - 1;
> >
> > (both assuming positive numbers only).
> > I suppose my question is whether b <= a, comparing
> > fixed and floating-point, involves any casting
> > that might slow down things.
> >
> > I would expect that if there is any casting it would
> > be long -> double; I suppose that does not carry
> > any penalty, or does it?
> >
> > Thanks
> >
> > Victor
> >
> >
> ----------------------------------------------------------
> > --------------- Using Tomcat but need to do more? Need
> > to support web services, security? Get stuff done
> quickly with pre-integrated technology to make your job
> > easier Download IBM WebSphere Application Server v.1.0.1
> > based on Apache Geronimo
>
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > _______________________________________________
> > Csound-devel mailing list
> > Csound-devel@lists.sourceforge.net
> >
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> >
>
> ----------------------------------------------------------
> --------------- Using Tomcat but need to do more? Need to
> support web services, security? Get stuff done quickly
> with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on
> Apache Geronimo
>
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-10-21 23:28
From"Steven Yi"
SubjectRe: [Cs-dev] which is faster?
AttachmentsNone  

Date2006-10-21 23:29
FromErik de Castro Lopo
SubjectRe: [Cs-dev] which is faster?
Victor Lazzarini wrote:

> Steven,
> 
> Erik's text in www.mega-nerd.com/FPcast explains
> it well.

:-)
 
> I went and tested the two options I gave here:
> lrint() + test is slower than just casting.
> lrint() on its own is faster than casting, but
> it rounds; if truncation is needed then we're
> better off with casting.

If you want truncation you are better off using the C99
trunc() function. The Linux man page says:

    NAME
       trunc, truncf, truncl - round to integer, towards zero

    SYNOPSIS
       #include 

       double trunc(double x);
       float truncf(float x);
       long double truncl(long double x);

       Compile with -std=c99; link with -lm.

    DESCRIPTION
       These functions round x to the nearest integer not larger in absolute value.

    RETURN VALUE
       The rounded integer value.  If x is integral, infinite or NaN, x itself is returned.

Cheers,
Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo
+-----------------------------------------------------------+
Diana West for President of the United States
http://www.washtimes.com/op-ed/20060817-091447-7758r.htm
http://www.washtimes.com/op-ed/20060824-084015-5082r.htm

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net