Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   Algorithm Timing (https://thetfp.com/tfp/tilted-technology/87243-algorithm-timing.html)

RAGEAngel9 04-14-2005 05:33 PM

Algorithm Timing
 
Hey guys quick question that I can't seem to get.
I'm trying to show how a program I wrote improves (or worsens) as the number of processors increases. However, I can't for the life of me determine a way to represent the time it take for one of the funcitons to run.


Code:

    double term = start;
    double newTerm = 0;
    double precision=1e-6;
    double sum = start;
    int i =0;
    // Calculate each new term and add to total
    //Stop when the previous term is less than the precision
    for( i = p;term > precision ; )
    {
        double newFac = 1;
        // Calculate the nessesary jump given i and the (n)umber of processors
        for(int j = 1;j <= n ; j++ )
        {
            newFac = newFac * ( x / ( i+ j ));
           
        }
        newTerm = newFac;
        //Get new term
        term = term * newTerm;
        // Increment sum by new term
        sum += term;
        i=i+n;
    }

I know the inner loop runs n times each time the main loop runs. But I can't figure out how to determine the number of times the main loop runs in any sort of formulaic way.

Yes, it's homework, but 90% of the assignment was developing and writing the algorithm.
Thanks

vinaur 04-14-2005 08:04 PM

Is this it, because I don't see any declarations for start, p and x. It would be nice to know what those are.

theFez 04-14-2005 08:21 PM

If you can use perl, there are some good benchmarking features in the benchmark module.

I've used them a few times to test performance of different algorithms.

http://www.perldoc.com/perl5.8.0/lib/Benchmark.html

SiNai 04-15-2005 01:15 PM

Are we talking theoretical big-oh stuff or empirical timing, or both? You can use System.currentTimeMillis() for actual timings in milliseconds.

Theoretical.. You're incrementing your outer loop by a constant? 0(n^2) then.. (Can't tell what n is..)


All times are GMT -8. The time now is 06:29 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62