Results 1 to 7 of 7

# Thread: Help me to analyse!!!

- 03-04-2009, 09:11 AM #1Member
- Join Date
- Mar 2009
- Posts
- 16

- Rep Power
- 0

## Help me to analyse!!!

I'm developing some algorithms using java.math.BigInteger and java.math.BigDecimal classes, but I have to analyze, how many computer operation is done when I use methods of these classes. For example I want to add value of the two BigInteger obejcts like 1234567890123456789012345678901234567890 and 9876543210987654321098765432109876543210 using BigInteger's add() method, so how many elementary computation is done to give me output? Or say in different how long does add() method takes, on computer with 1.000.000 elementary operations per second, to add those BigIntegers?

- 03-04-2009, 10:03 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1

- Rep Power
- 26

You want to know the time taken to do this, or how many operations take place in that calculation?

Do you know anything about Z80 or something low level language?

- 03-04-2009, 10:12 AM #3Member
- Join Date
- Mar 2009
- Posts
- 16

- Rep Power
- 0

Eranga, I do not know about Z80 low language. I need to know how many operations take place in that calculation. Can you advise me? I need result with equation, which include parameters of computer's frequency.

- 03-04-2009, 10:27 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1

- Rep Power
- 26

So you can think about the number of iteration you take to calculate those numbers, just build-up the logic first and added into an equation.

- 03-04-2009, 10:33 AM #5Member
- Join Date
- Mar 2009
- Posts
- 16

- Rep Power
- 0

So I wrote program:

import java.math.BigDecimal;

class Sqrt {

BigDecimal sqrt2() {

BigDecimal x = new BigDecimal("1");

BigDecimal a = new BigDecimal("0");

BigDecimal ikki = new BigDecimal("2");

BigDecimal yarim = new BigDecimal("0.5");

for (int i=0; i<=7; i++) {

a=ikki.divide(x, 300, 0);

x=x.add(a);

x=x.multiply(yarim);

}

return x;

}

}

class SquareRoot {

public static void main(String args[]) {

Sqrt sqrt = new Sqrt();

System.out.println(sqrt.sqrt2());

}

}

Look at

a=ikki.divide(x, 300, 0);

x=x.add(a);

x=x.multiply(yarim);

I do not know how many operations ,for example, in method add(), because it's different simple plus (+). What do you think?

I don't need this (the fragment gives result how many time program worked):

long t1 = System.currentTimeMillis();

x=x.add(a);

long time = System.currentTimeMillis() - t1;

Sorry for my poor english...

- 03-04-2009, 12:45 PM #6Member
- Join Date
- Mar 2009
- Posts
- 16

- Rep Power
- 0

Nobody wants to help me... :(

- 03-05-2009, 01:38 PM #7
Olim:

What you are looking for is the number of machine cycles for each command? Part of what your looking for is the assembler commands (low lelvel) equivalent of those operations (try Google). You are correct in stating that System.currentTimeMillis() is not what you are looking for. The only thing I can think of is using a dissambler. DOS comes with one (not in the help) called "debug" , but I used so long ago, I have forgotten what it all does (again try Google with "DOS debug commands"). But to understand what your looking for you would have to understand the assembler language.

Luck,

CJSL**Chris S.**

**Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.**

## Bookmarks