473,396 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

low speed logaritmith calculation

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
--
Roger
Nov 17 '05 #1
5 1307
rogerzar wrote:
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?


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
Nov 17 '05 #2
On Tue, 22 Feb 2005 16:41:01 -0800, "rogerzar"
<ro******@discussions.microsoft.com> wrote:
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


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
Nov 17 '05 #3
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

"Severian" wrote:
On Tue, 22 Feb 2005 16:41:01 -0800, "rogerzar"
<ro******@discussions.microsoft.com> wrote:
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


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

Nov 17 '05 #4
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

"mosimu" <mo****@discussions.microsoft.com> wrote in message
news:18**********************************@microsof t.com...
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

"Severian" wrote:
On Tue, 22 Feb 2005 16:41:01 -0800, "rogerzar"
<ro******@discussions.microsoft.com> wrote:
>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


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

Nov 17 '05 #5
Carl Daniel [VC++ MVP] wrote:
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?

--
Andrea Sansottera
UGIdotNET [Italian] http://www.ugidotnet.org
My weblog [Italian] http://blogs.ugidotnet.org/andrew/
Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: m004202002 | last post by:
I recently visited a site http://us.mcafee.com/root/speedometer/default.asp which find out the connection speed . Can any body explain how(logic) to do it ? Can i do that using php ? Please help...
34
by: Jacek Generowicz | last post by:
I have a program in which I make very good use of a memoizer: def memoize(callable): cache = {} def proxy(*args): try: return cache except KeyError: return cache.setdefault(args,...
29
by: Bart Nessux | last post by:
Just fooling around this weekend. Wrote and timed programs in C, Perl and Python. Each Program counts to 1,000,000 and prints each number to the console as it counts. I was a bit surprised. I'm not...
8
by: ted | last post by:
How does the speed of the Scons build tool compare with Ant? Right now with out Ant builds take around an hour. Hoping to speed that up. TIA, Ted
12
by: Marty | last post by:
Hi, I am building an application that need high speed of execution. There is a lot of string parsing that I do in VB.NET. Do I gain in speed if all that string parsing is made in a dll coded...
2
by: Chris Ochs | last post by:
I am pretty sure I know this already, but every time you run a Pl/Perl function it is just like running a perl script as far as having to load and compile the code right? My application runs under...
5
by: David | last post by:
HI all: I am write a programme has lots exp() (scientific calculation). It seems that the function in math.h are of double precision. When my declare data set as float type... it is even slower...
4
by: wang frank | last post by:
Hi, While comparing the speed of octave and matlab, I decided to do a similar test for python and matlab. The result shows that python is slower than matlab by a factor of 5. It is not bad since...
17
by: Suresh Pillai | last post by:
I am performing simulations on networks (graphs). I have a question on speed of execution (assuming very ample memory for now). I simplify the details of my simulation below, as the question I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.