bug-libmatheval
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-libmatheval] derivatives vs new functions


From: Aleksandar B. Samardzic
Subject: Re: [Bug-libmatheval] derivatives vs new functions
Date: Mon, 10 Oct 2005 09:45:34 +0200
User-agent: Mutt/1.4.2.1i

On Sun, Oct 09, 2005 at 01:45:10AM +0200, Giulio Bottazzi wrote:
> Hello,
> I want to share with you the result of a recent test I did. I was
> curious how much slow is libmatheval compared to some other
> "more optimized" software. I found a similar project, named "Formulc".
> You can find it here 
> 
> http://www.cs.brandeis.edu/~hhelf/formu/formulc.html
> 
> it does not implement the symbolic derivative neither the automatic
> recognition of variables, both featured in libmatheval. I'm not an
> expert of this kind of coding, but based on a previous posting by Alex
> (it's reported below) I expected quite poor libmatheval performances.
> Well, I discovered that it is not the case! Consider this function
> 
> f = exp(x^2+2*x+1.) + sin(3*tan(x))^(3.2) + 0.1
> 
> the computation of f on 1,000,0000 random numbers in [0,1] gave this
> results on my machine at home
> 
> direct:   1.450000 sec
> formulc:  2.290000 sec
> matheval: 2.420000 sec
> 
> where "direct" means the use of a coded C function. As you can see, the
> speed of libmatheval is quite comparable to the speed of formulc. I
> tried various functions, always obtaining similar results. In
> conclusions, the features implemented in libmatheval do not seem to lead
> to an excessive slow-down in the generated code. Given its
> extra-features, I would consider it the clear winner.
> 
> Any comment?

I looked a bit into formulc and, as far as I can understand regarding
how it is structured, results you measured are to be expected.  Namely,
both libraries are spending some setup time in transforming the
expression in a form convenient for calculations (libmatheval into a
tree, formulc into postfix form) and then are traversing this form of
expression in order to calculate the value of the expression.  Setup
time is small compared to calculation time for given number of
calculations and postfix form is slightly faster to traverse than tree
form, thus the difference (and I guess even random numbers calculation
is flattening comparison a bit).  Regarding derivatives, note that
libmatheval is not doing anything related until you call
evaluator_derivative() function, so no loss of time there in your tests.
So overall, we could conclude postfix form of representing expressions,
used by formulc, is slightly better than tree form, used by libmatheval.
But anyway - I was actually already tinkering about changing
expressions representation to postfix (or prefix, whatever) form for an
eventual libmatheval internals re-design, so I found your tests very
useful.

Regards,
Alex





reply via email to

[Prev in Thread] Current Thread [Next in Thread]