Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2005

Tip: Looking for answers? Try searching our database.

Performance Breakdown Writing to Memory Location

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chucker - 28 Oct 2005 14:52 GMT
Hi Folks!

For some reasons, this code:

>    float tmp = 0.;
>     for (int i = 0; i < 2000; i++) {
>         for (int j = i; j < 2000; j++) {
>             for (int k = 0; k < 9000; k++) {
>                 tmp += tmp_mat(k,i) * tmp_mat(k,j);
>             }
>             tmp = 0.;
>
>         }
>         cout << "J: " << i  << endl;
>     }

is 10-100 times faster than this

>    float tmp = 0.;
>     for (int i = 0; i < 2000; i++) {
>         for (int j = i; j < 2000; j++) {
>             for (int k = 0; k < 9000; k++) {
>                 tmp += tmp_mat(k,i) * tmp_mat(k,j);
>             }
>            data2d[i][j] = tmp;    // the problem
>             tmp = 0.;
>
>         }
>         cout << "J: " << i  << endl;
>     }

Why is assigning a value that slow?

can anybody help me?

Thanks in advance for your efforts

-Chucker
Carl Daniel [VC++ MVP] - 28 Oct 2005 15:49 GMT
> Hi Folks!
>
[quoted text clipped - 28 lines]
>
> Why is assigning a value that slow?

What is tmp_mat?  what's data2d?

First off, I hope you're measuring a release build as debug build timings
are pretty close to meaningless.

Secondly, in the first loop, tmp is probably stored in a floating point
register for the entire operation, while the second form has to make an
additional 4,000,000 memory writes.  That's got to take a bit of time.

-cd
Chucker - 31 Oct 2005 15:41 GMT
Sorry, maybe I did not make myself clear.

1.) All the "unknown" variables are float types

2.) I know that loop 1 does not write to a memory location. I am looking for
the most performant way to do this.

Thanks

Chucker

> > Hi Folks!
> >
[quoted text clipped - 39 lines]
>
> -cd
Carl Daniel [VC++ MVP] - 31 Oct 2005 16:12 GMT
> Sorry, maybe I did not make myself clear.
>
> 1.) All the "unknown" variables are float types

OK.

> 2.) I know that loop 1 does not write to a memory location. I am
> looking for the most performant way to do this.

You may have already found it.  Have you looked at a disassembly of the
first loop (without the writes)?  In an optimized build, the compiler may
have simply omitted much (or all) of the loop if it can prove that the only
side-effect of the whole thing is to assign 0.0 to tmp.

-cd

> Thanks
>
[quoted text clipped - 44 lines]
>>
>> -cd

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.