Thread: How do you compare?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212

    Wink How do you compare?

    I wrote a hackish benchmark program so you can compare your computers to my aging little machine



    here's the code
    Code:
    #include <iostream>
    #include <cstring>
    #include <ctime>
    
    using namespace std;
    int sl;
    
    void inline swt(unsigned char *tp, int x, int y)
    {
    	char tmp;
    	tmp = tp[x];
    	tp[x] = tp[y];
    	tp[y] = tmp;
    }
    
    void inline perm(unsigned char *tp, int pl)
    {
    	if (pl == sl - 1) {
    	//	cout << tp << endl;
    	}
    	for (int nc = pl; nc < sl; nc++) {
    	        swt(tp, pl, nc);
    		perm(tp, pl + 1);
    	}
    }
    
    int main(void)
    {
    	unsigned char str[] = "nosebleeding";
    	double brispeed = 26.8300F;
    	double bripercent = brispeed / 100;
    	double yourspeed;
    	double yourpercent;
    	clock_t start, end;
    
    	sl = strlen((const char*)str);
    	start = clock();
    	perm(str, 0);
    	end = clock();
    
    	yourspeed = (double)(end - start) / (double)CLOCKS_PER_SEC;
    	yourpercent = yourspeed / bripercent;
    	cout << "The program took "
    	     << yourspeed
    	     << " seconds. That's " << yourpercent << "% of the time "
    	     << "Brian's computer took." << endl;
    
    	return 0;
    }
    note: the lower the percentage the better.

    my output:
    Code:
    bash-2.05b$ ./test
    The program took 26.8216 seconds. That's 99.9687% of the time Brian's computer
    took.
    Code:
    Specs:
    1.00GHz AMD Athlon
    512MB RAM
    FreeBSD 4.9
    GCC 3.3.3
    this will be wildly inaccurate due to compiler optimisations and such, but it's just for fun.
    Last edited by Brian; 11-09-2003 at 12:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. compare strings not working
    By gtriarhos in forum C Programming
    Replies: 7
    Last Post: 09-29-2005, 12:51 PM
  3. Help Writing My Own String Compare
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 04-07-2005, 09:44 PM
  4. String Compare Using Dynamic Arrays
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 03-31-2005, 08:01 PM
  5. string compare
    By IceBall in forum C Programming
    Replies: 4
    Last Post: 10-12-2003, 05:26 PM