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++ / February 2005

Tip: Looking for answers? Try searching our database.

low speed logaritmith calculation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rogerzar - 23 Feb 2005 00:41 GMT
Hi all

In my application I am displaying bipmap image
I am using the log10() function, but it takes very
long time to display the image, the pixel array size is
1272x1003 pixels.

I am looking for a some tricks thats helpme to
improve the speed of this function

below find a pice of code that I am using

for (i=0;i<iDepth;i++)
{
   for (j=0;j<aLength;j++)
   {
   lpBmpValue = lpBmp1 + j + i*(iDepth+2);
   *lpBmpValue =dContrast*(10*log10(S[i][j])+dBrightness);
     
   }
}
this part of the code takes 200mSec

Is it possible to improbe?
Thanks
Signature

Roger

Carl Daniel [VC++ MVP] - 23 Feb 2005 02:09 GMT
> Hi all
>
[quoted text clipped - 20 lines]
>
> Is it possible to improbe?

Use a table of logarithms instead of calculating it.  You didn't show any of
the types involved, but presumably you're using 8 bits per pixel (or per
component), so a 256-entry table would suffice.

-cd
Andrea Sansottera - 24 Feb 2005 11:18 GMT
> Use a table of logarithms instead of calculating it.  You didn't show any of
> the types involved, but presumably you're using 8 bits per pixel (or per
> component), so a 256-entry table would suffice.

Another solution could be to approximate the logaritm function with
precomputated taylor polynomials (it depends on the precision you need),
maybe it may be a little faster... but I'm not sure about that. Any opinion?

Signature

Andrea Sansottera
UGIdotNET [Italian] http://www.ugidotnet.org
My weblog [Italian] http://blogs.ugidotnet.org/andrew/

Severian - 23 Feb 2005 07:11 GMT
>Hi all
>
[quoted text clipped - 18 lines]
>}
>this part of the code takes 200mSec

I don't know the type of S[][], but even if it is double you can
probably create a reasonable table of doubles, there is a range limit
on the output (one byte I assume), so accuracy is not the ultimate
need. You need sufficient accuracy to produce valid output.

If S[][] are bytes, you need a simple 256-byte lookup table, as Carl
suggested. Otherwise, you may need a bit wider table -- but I would
think no larger than 64KB. if S[][] are doubles, you'll need to reduce
them to fit the table; but considering the limited output range, this
shouldn't be a problem.

Once built, this table will allow you to do your calculations in a
tiny amount of time.

--
Sev
mosimu - 23 Feb 2005 21:01 GMT
You can simplify one of the inner equations like so.  Multiplying two
thirty-two bit numbers takes many cycles.

for (i=0;i<iDepth;i++) {
  int c = i*(iDepth+2);
  for (j=0;j<aLength;j++) {
     lpBmpValue = lpBmp1 + j + c;
     *lpBmpValue =dContrast*(10*log10(S[i][j])+dBrightness);
  }
}

mosimu

> >Hi all
> >
[quoted text clipped - 35 lines]
> --
> Sev
Steve McLellan - 23 Feb 2005 21:41 GMT
The log is definitely where the performance is going though; one of our
applications (without the vectorised maths code we use) spends over 20% of
its calculation time in each of a log and exponential calculation that can't
be tabulated unlike (as Carl pointed out) this case. We've found this on
both PCs and Macs, where other maths operations are relatively inexpensive.

Steve

> You can simplify one of the inner equations like so.  Multiplying two
> thirty-two bit numbers takes many cycles.
[quoted text clipped - 48 lines]
>> --
>> Sev

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.