Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

unexpected execution time crosscheck

88 views
Skip to first unread message

Walter Roberson

unread,
Sep 10, 2010, 6:06:12 PM9/10/10
to
I would appreciate if some people could save and run the following simple
function in different versions and see if they see the same performance that I
see.

In R2008b Linux 64, the first (single-line) loop takes a bit less than half of
the time of the same code written out across multiple lines if the argument 0
is given, and a bit more than half of the multiline version if the argument 1
is given.

My impression from previous discussions is that the single-line version was
more difficult for the JIT to deal with; I would thus expect the single-line
version to be either the same magnitude of time or slower than the multi-line
version ?

I recall reading that 2010a had significant JIT improvements so perhaps the
2010 releases have very different time scales than I observed.


Also, I would appreciate if you could run the same routine under the profiler.
When I do that, the timing for the single-line version stays about the same,
but the timing for the multi-line version increases by about a factor of 10. I
would have expected the profiler to be implemented in such a way that relative
timing were not affected (at least not by much)


To run, invoke

testif(0)
or
testif(1)


function testif(v)
thisstate = double(v);
disp('double');
c = 0;tic;for k = 1:20000;if thisstate; c=c+1;end;end;toc

thisstate = double(v);
disp('double multiline');
c = 0;
tic;
for k = 1:20000
if thisstate
c=c+1;
end
end
toc
end


(I noticed this oddity while I was timing which data type was the fastest to
test in "if" statements. Answer: double is almost always the fastest, though
logical occasionally is faster. uint8 is measurably slower to test.)

Bruno Luong

unread,
Sep 10, 2010, 6:37:06 PM9/10/10
to
My configuration: 2010B 64 bit, Windows 7, Laptop i5

>> testif(0)
double
Elapsed time is 0.000820 seconds.
double multiline
Elapsed time is 0.000225 seconds.
>> testif(1)
double
Elapsed time is 0.001135 seconds.
double multiline
Elapsed time is 0.000299 seconds.
>>

Walter Roberson

unread,
Sep 10, 2010, 6:38:25 PM9/10/10
to

Thanks, Bruno; those are quite different than what I see 2008b. It will be
interesting to see which release first fixed the issue.

per isakson

unread,
Sep 11, 2010, 3:49:03 PM9/11/10
to
R2010a 64bit, Windows 7, cpu Q9400

>> testif(0)
double
Elapsed time is 0.000447 seconds.
double multiline
Elapsed time is 0.000171 seconds.
>> testif(1)
double
Elapsed time is 0.000785 seconds.
double multiline
Elapsed time is 0.000178 seconds.

>> profile on
>> testif(1)
double
Elapsed time is 0.000747 seconds.
double multiline
Elapsed time is 0.010959 seconds.

>> profile on
>> testif(0)
double
Elapsed time is 0.000394 seconds.
double multiline
Elapsed time is 0.004756 seconds.

/per

Tristram Scott

unread,
Sep 13, 2010, 5:00:59 AM9/13/10
to
Hi Walter,

Interesting test you have come up with. I have run it against all the
MATLAB releases I have at hand, but you have me curious, so I might see if
I can fill in some gaps in the list of releases. I have tabulated results
in rows to save some space. They are in the order of testif(0) double,
double multiline, testif(1) double, double multiline.

The results for the Linux versions seem very similar to each other, so I
think I will need to look back a bit further in the release history.

The Solaris results show quite some change across the releases, and
certainly not always for the better. Interesting to me is that MATLAB 6.5
seems to be about as good as it gets under Solaris. It has always been my
preferred version, except when I have a need for 64 bit, in which case
5.3.1 was good until R2009a finally offered 64 bit capabilities once more.

I have run all of these with the -nodesktop flag, except MATLAB 5.3.1 under
Solaris, and the second run of MATLAB 6.5 under Solaris, where I used
-nojvm for a bit of extra speed.

At this point I have results for the following:

=======================
Linux:
Ubuntu 10.04 running under VirtualBox on a Sun Ultra 24 (Intel Quad
core 3.0GHz). Host OS is Solaris 10 05/09.
=======================

MATLAB 7.6.0.324 (R2008a)
=======================
0.000357 0.000107 0.000439 0.000106
>> profile on
0.000321 0.000647 0.000390 0.001242

MATLAB 7.7.0.471 (R2008b)
=======================
0.000357 0.000085 0.000423 0.000094
>> profile on
0.000342 0.000653 0.000423 0.001255

MATLAB 7.8.0.347 (R2009a) 64-bit (glnxa64)
=======================
0.000328 0.000091 0.000392 0.000091
>> profile on
0.000314 0.000653 0.000392 0.001249

=======================
SunFire 280R, 2 x 1.2GHz (SPARC), Solaris 10 05/09
=======================

MATLAB 5.3.1.29215a (R11.1)
=======================
0.0145 0.0160 0.0369 0.0420
>> profile on
0.0133 0.0813 0.0446 0.1793

MATLAB 6.5.0.180913a Release 13
=======================
0.0022 0.0020 0.0026 0.0026
>> profile on
0.0020 0.1203 0.0027 0.2356

MATLAB 7.0.4.352 (R14) Service Pack 2
=======================
0.001695 0.002505 0.002184 0.003948
>> profile on
0.001562 0.156719 0.002157 0.311997

MATLAB 7.1.0.183 (R14) Service Pack 3
=======================
0.001550 0.002724 0.002031 0.003865
>> profile on
0.001563 0.157677 0.002110 0.312204

MATLAB 7.7.0.471 (R2008b)
=======================
0.002062 0.003321 0.003177 0.005704
>> profile on
0.002085 0.009706 0.003282 0.018474

MATLAB 7.8.0.347 (R2009a) 64-bit (sol64)
=======================
0.002083 0.003464 0.003395 0.005903
>> profile on
0.002106 0.010328 0.003248 0.018446

MATLAB 6.5.0.180913a Release 13, -nojvm
=======================
0.0022 0.0020 0.0026 0.0026
>> profile on
0.0020 0.0696 0.0026 0.1374

--
Dr Tristram J. Scott
Energy Consultant

0 new messages