Home World Forum
Stars! AutoHost web forums

Jump to Stars! AutoHost


 
 
Home » Stars! Clones, Extensions, Modding » FreeStars » Efficient Algorithm for Scanning planets/fleets/etc.
Re: Efficient Algorithm for Scanning planets/fleets/etc. Fri, 09 February 2007 15:42 Go to previous messageGo to previous message
Kotk

 
Commander

Messages: 1227
Registered: May 2003
C++ compilers tend to optimize the code like you posted entirely out so i somewhat modified it to give any usage to the variables there... and also to measure the time directly in code. Somehow i get here different results than you. Maybe i just know C# not well enough and do something wrong with it. Other possibilities are that you run not "C++" but "managed C++" or that you run "Debug" version of C++. On that case your computer seems about 4 times better than mine. Very Happy

//C# code

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime time1 = DateTime.Now;
            double d1 = 0.727272;
            double d2 = 0.26252;
            double d3 = 343432.232;

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

                d3 = d1 * d2;
                d1 = d3 * d2;
                d2 = d2 * d2;
                d3 = d1 * d2;
                d3 = d3 * d2;
            }
            DateTime time2 = DateTime.Now;

            TimeSpan span = time2 - time1;
            
            Console.WriteLine("{0};{1};{2};{3}",span, d1,d2,d3);
        }
    }
}


Displays:
00:00:02.1089395;0;0;0
I get it means 2109 milliseconds?

//C++ code

#include "stdafx.h"
#include <sys/timeb.h>
#include <sys/types.h>
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{

    timeb time1;
    ftime(&time1);
    double d1 = 0.727272;
    double d2 = 0.26252;
    double d3 = 343432.232;

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

        d3 = d1 * d2;
        d1 = d3 * d2;
        d2 = d2 * d2;
        d3 = d1 * d2;
        d3 = d3 * d2;
    }
    timeb time2;
    ftime(&time2);
 
    std::cout << (time2.time - time1.time)*1000 + time2.millitm - time1.millitm 
        << ";" << d1 << ";" << d2 << ";" << d3 << "\n";
    char c;
    std::cin >> c;
    
    return 0;
}


Displays:
594;0;0;0

C++ runs bit less than 4 times quicker but not much.
Both examples were compiled with very same Visual Studio 2005 Professional.


[Updated on: Fri, 09 February 2007 15:54]

Report message to a moderator

 
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: New stars! server clone proposal
Next Topic: 3D tool
Goto Forum:
  


Current Time: Mon Apr 29 10:46:30 EDT 2024