Moritz Lenz > Math-Expression-Evaluator > Math::Expression::Evaluator::Optimizer

Download:
Math-Expression-Evaluator-v0.3.2.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Stalled  1
View/Report Bugs
Source  

NAME ^

Math::Expression::Evaluator::Optimizer - Optimize Math::Expression::Evaluator ASTs

SYNOPSIS ^

    use Math::Expression::Evaluator;
    my $m = Math::Expression::Evaluator->new("2 + 4*f");
    $m->optimize();
    for (0..100){
        print $m->val({f => $_}), "\n";
    }

DESCRIPTION ^

Math::Expression::Evaluator::Optimizer performs simple optimizations on the abstract syntax tree from Math::Expression::Evaluator.

You should not use this module directly, but interface it via Math::Expression::Evaluator.

The following optimizations are implemented:

PERFORMANCE CONSIDERATIONS ^

optimize() currently takes two full loops through the AST, copying and recreating it. If you execute val() only once, calling optimize() is in fact a performance loss.

If the expression is optimizable, and you execute it $n times, you usually have a net gain over unoptimized execution if $n > 15.

Of course that value depends on the complexity of the expression, and how well it can be reduced by the implemented optimizations.

Your best is to always benchmark what you do. Most of the time the compiled version returned by ->compiled is much faster than the optimized (and not compiled) form.

syntax highlighting: