Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-03-23 13:21:59


Am Freitag, 23. März 2007 18:02 schrieb Stephen Gross:
> I've been testing out the performance of assigning individual
> elements in a matrix. I have a pretty simple code snippet that
> creates an NxN matrix, loops across the elements, and assigns them
> repeatedly. I tried it out first using the matrix's operator(), and
> then using a pointer to the underlying array. I found that accessing
> the array directly was a *lot* faster! Is this correct? Should I
> expect to see better performance here? I would have thought that
> simple element access would be pretty fast already...?
>
> Any thoughts?

I agree for the debug mode (default). This is because bounds are checked
on each access.

(debug mode)
op(): 10.03s
pointer: 0.89s

(release without compiler optimizations, -DNDEBUG)
op() 5.22s
pointer 0.89s

(release with compiler optimizations, -DNDEBUG -O2)
op() 0.16s
pointer 0.17s

You see no difference for the last version.

mfg
Gunter