octave-maintainers
[Top][All Lists]
Advanced

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

Accessing in-place optimizations


From: Rik
Subject: Accessing in-place optimizations
Date: Mon, 21 Nov 2011 21:03:48 -0800

Since release 3.4.0 the operation-assignment operators, such as +=, have
been optimized to operate in place on the data.  This makes them very
fast.  I just did some benchmarking on the following equivalent code segments.

x = x + 1       Elapsed time is 2.23616 seconds.
x++               Elapsed time is 1.50738 seconds.
x += 1           Elapsed time is 0.724228 seconds.

So the results are roughly 3X, 2X, 1X with in-place assignment being the
fastest.

Would it be possible for the parser to recognize the first construction
(var = var + ???) and map it to the same code that the '+=' operator uses? 
I have the same question for the increment operator since that is clearly
an in-place operation.

All of the results hold for the decrement operator as well.  Indeed, any of
the operator-assigment operators seem to be faster than the regular
equivalent.  Even trivial operators like unary minus are faster with
operation-assignment operators.

x = -x          3X
x *= -1        1X

The script I used for benchmarking is attached.

Cheers,
Rik

Attachment: bm_accum.m
Description: Text Data


reply via email to

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