Example #1
0
    // Use this for initialization
    void Start()
    {
        if (SVGFile != null) {
          Stopwatch w = new Stopwatch();

          w.Reset();
          w.Start();
          ISVGDevice device;
          if(useFastButBloatedRenderer)
        device = new SVGDeviceFast();
          else
        device = new SVGDeviceSmall();
          m_implement = new Implement(this.SVGFile, device);
          w.Stop();
          long c = w.ElapsedMilliseconds;

          w.Reset();
          w.Start();
          m_implement.StartProcess();
          w.Stop();
          long p = w.ElapsedMilliseconds;

          w.Reset();
          w.Start();
          renderer.material.mainTexture = m_implement.GetTexture();
          w.Stop();
          long r = w.ElapsedMilliseconds;
          UnityEngine.Debug.Log("Construction: " + Format(c) + ", Processing: " + Format(p) + ", Rendering: " + Format(r));

          Vector2 ts = renderer.material.mainTextureScale;
          ts.x *= -1;
          renderer.material.mainTextureScale = ts;
          renderer.material.mainTexture.filterMode = FilterMode.Trilinear;
        }
    }
Example #2
0
    public static void Main(string[] args)
    {
        Stopwatch sw = new Stopwatch();
        int status;

        // Generate input data
        sw.Start();
        const int SIZE = 384;

        List<int> firstVector = new List<int>();
        List<int> secondVector = new List<int>();

        const int Scalar = 3;

        Random random = new Random();
        for (int i = 0; i < SIZE; i++)
        {
                firstVector.Add(random.Next(0, 100));
                secondVector.Add(random.Next(0, 100));
        }

        sw.Stop();
        Console.WriteLine("Generating input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        // DFE Output
        sw.Reset();
        sw.Start();
        List<int> dataOutDFE = VectorAdditionDfe(SIZE, firstVector, secondVector, Scalar);
        sw.Stop();
        Console.WriteLine("DFE vector addition total time:\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        // CPU Output
        sw.Reset();
        sw.Start();
        List<int> dataOutCPU = VectorAdditionCpu(SIZE, firstVector, secondVector, Scalar);
        sw.Stop();
        Console.WriteLine("CPU vector addition time:\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        // Checking results
        sw.Reset();
        sw.Start();
        status = Check(dataOutDFE, dataOutCPU, SIZE);
        sw.Stop();
        Console.WriteLine("Checking results:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        if (status > 0)
        {
            Console.WriteLine("Test failed {0} times! ", status);
            Environment.Exit(-1);
        }
        else
        {
            Console.WriteLine("Test passed!");
        }
    }
Example #3
0
    /// <summary> Calculates simpleDfe and simpleCpu and
    /// checks if they return the same value. 
    /// </summary>
    /// <param name = "args"> Command line arguments </param>
    public static void Main(string[] args)
    {
        Stopwatch sw = new Stopwatch();
        int status;

        sw.Start();
        const int SIZE = 1024;
        List<double> dataIn = new List<double>();

        for (int i = 0; i < SIZE; i++)
        {
            dataIn.Add(i + 1);
        }

        sw.Stop();
        Console.WriteLine("Generating input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        // DFE Output
        sw.Reset();
        sw.Start();
        List<double> dataOutDFE = SimpleDFE(SIZE, dataIn);
        sw.Stop();
        Console.WriteLine("DFE simple total time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        // CPU Output
        sw.Reset();
        sw.Start();
        List<double> dataOutCPU = SimpleCPU(SIZE, dataIn);
        sw.Stop();
        Console.WriteLine("CPU simple total time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        // Checking results
        sw.Reset();
        sw.Start();
        status = Check(dataOutDFE, dataOutCPU, SIZE);
        sw.Stop();
        Console.WriteLine("Checking results:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        if (status > 0)
        {
            Console.WriteLine("Test failed {0} times! ", status);
            Environment.Exit(-1);
        }
        else
        {
            Console.WriteLine("Test passed!");
        }
    }
Example #4
0
    void Start()
    {
        Stopwatch timer = new Stopwatch();
        timer.Start();
        worldTree = new WorldTree(8);
        //worldTree.ExpandNode(3);

        TestWTI2(30);

        timer.Stop();
           // DumpToFile("WorldTreeDump2.txt");

        DebugOutput.Shout("timer says: " + timer.ElapsedMilliseconds.ToString());

        DebugOutput.Shout("there is " + worldTree.GetIndiceCount().ToString() + " nodes");
        timer.Reset();
        timer.Start();

        TestWTI2(10);
        //DumpToFile("WorldTreeDump.txt");

        //TestWTI2();
        //TestWTI(new Vector3(14, 14,14));

        timer.Stop();
        wti = new WorldTreeInterface(worldTree, transform.position);

        DebugOutput.Shout("timer says: " + timer.ElapsedMilliseconds.ToString());
        DebugOutput.Shout("there is " + worldTree.GetIndiceCount().ToString() + " nodes");

        DumpToFile("WorldTreeDump.txt");
        wti.DumpAllToFile("WTIDump.txt");
    }
Example #5
0
 static void Main()
 {
     Database db = new Database();
     using (db)
     {
         var employees = db.Employees;
         Stopwatch sw = new Stopwatch();
         Console.WriteLine("EmployeeName | EmployeeDepartment | EmployeeTown");
         sw.Start();
         foreach (var item in employees)
         {
             Console.WriteLine("{0} | {1} | {2}", item.FirstName, item.Department.Name, item.Address.Town.Name);
         }
         sw.Stop();
         Console.WriteLine();
         Console.WriteLine("Time with problem N+1: {0}", sw.Elapsed);
         Console.WriteLine("338 queryes with proffiler");
         Console.WriteLine("------------------------------------------------------------");
         sw.Reset();
         sw.Start();
         foreach (var item in employees.Include("Department").Include("Address.Town"))
         {
             Console.WriteLine("{0} | {1} | {2}", item.FirstName, item.Department.Name, item.Address.Town.Name);
         }
         sw.Stop();
         Console.WriteLine("Time withouth problem N+1: {0}", sw.Elapsed);
         Console.WriteLine("1 queryes with proffiler");
     }
     
 }
Example #6
0
    public static void Main()
    {
        Stopwatch watch = new Stopwatch();
        Random rand = new Random();
        watch.Start();
        for (int i = 0; i < iterations; i++)
            DayOfYear1(rand.Next(1, 13), rand.Next(1, 29));
        watch.Stop();
        Console.WriteLine("Local array: " + watch.Elapsed);
        watch.Reset();
        watch.Start();
        for (int i = 0; i < iterations; i++)
            DayOfYear2(rand.Next(1, 13), rand.Next(1, 29));
        watch.Stop();
        Console.WriteLine("Static array: " + watch.Elapsed);

        // trying to modify static int []
        daysCumulativeDays[0] = 18;
        foreach (int days in daysCumulativeDays)
        {
            Console.Write("{0}, ", days);
        }
        Console.WriteLine("");

        // MY_STR_CONST = "NOT CONST";
    }
Example #7
0
        static void Main()
        {
            var list = new List<int>();
            list.AddRange(Enumerable.Range(1, short.MaxValue/2));

            var watch = new Stopwatch();

            watch.Start();
            var result1 = Method1(list);
            watch.Stop();

            Console.WriteLine("Elapsed Ticks for Method1: {0}, with result: {1}", watch.ElapsedTicks, result1);
            var watch1Ticks = watch.ElapsedTicks;

            watch.Reset();
            watch.Start();
            var result2 = Method2(list);
            watch.Stop();

            Console.WriteLine("Elapsed Ticks for Method2: {0}, with result: {1}", watch.ElapsedTicks, result2);
            var watch2Ticks = watch.ElapsedTicks;
            double result = (double) watch1Ticks / watch2Ticks - 1.0; 
            Console.WriteLine("Method2 is faster that Method1 in {0:P}", result);

            Console.ReadKey();
        }
    //Float operations
    public static TimeSpan MesureFloatOperationsPerformance(float num, string operation, Stopwatch stopwatch)
    {
        stopwatch.Reset();
        switch (operation)
        {
            case "square root":
                {
                    stopwatch.Start();
                    Math.Sqrt(num);
                    stopwatch.Stop();

                    return stopwatch.Elapsed;
                }
            case "natural logarithm":
                {
                    stopwatch.Start();
                    Math.Log(num);
                    stopwatch.Stop();

                    return stopwatch.Elapsed;
                }
            case "sinus":
                {
                    stopwatch.Start();
                    Math.Sin(num);
                    stopwatch.Stop();

                    return stopwatch.Elapsed;
                }
            default:
                throw new ArgumentException("Invalid operations");
        }
    }
Example #9
0
        public void TestCanUpdateCustomer()
        {
            JsonServiceClient client = new JsonServiceClient("http://localhost:2337/");
            //Force cache
            client.Get(new GetCustomer { Id = 1 });
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            var cachedResponse = client.Get(new GetCustomer { Id = 1 });
            stopwatch.Stop();
            var cachedTime = stopwatch.ElapsedTicks;
            stopwatch.Reset();

            client.Put(new UpdateCustomer { Id = 1, Name = "Johno" });

            stopwatch.Start();
            var nonCachedResponse = client.Get(new GetCustomer { Id = 1 });
            stopwatch.Stop();
            var nonCacheTime = stopwatch.ElapsedTicks;

            Assert.That(cachedResponse.Result, Is.Not.Null);
            Assert.That(cachedResponse.Result.Orders.Count, Is.EqualTo(5));

            Assert.That(nonCachedResponse.Result, Is.Not.Null);
            Assert.That(nonCachedResponse.Result.Orders.Count, Is.EqualTo(5));
            Assert.That(nonCachedResponse.Result.Name, Is.EqualTo("Johno"));

            Assert.That(cachedTime, Is.LessThan(nonCacheTime));
        }
    private static void Main()
    {
        Stopwatch timer = new Stopwatch();
        timer.Start();
        Console.WriteLine("Creating products data.....");
        OrderedMultiDictionary<double, string> products = GenerateProducts();
        timer.Stop();
        Console.WriteLine("Time needed: "+timer.Elapsed);
        timer.Reset();
        double lowestPrice = randomNumberGenerator.NextDouble() * (MaxPrice/2 - MinPrice) + MinPrice;
        double highestPrice = randomNumberGenerator.NextDouble() * (MaxPrice - lowestPrice) + lowestPrice;
        bool isFirstSearch = true;
        timer.Start();

        for (int i = 0; i < CountSearches; i++)
        {
            IEnumerable<KeyValuePair<double, ICollection<string>>> extract = products.Range(lowestPrice, true, highestPrice, true).Take(CountResults);
            if (isFirstSearch)
            {
                timer.Stop();
                Console.WriteLine("First search result");
                Console.WriteLine("Price range from {0:F2} to {1:F2}:", lowestPrice, highestPrice);
                PrintSearchResults(extract);
                isFirstSearch = false;
                Console.WriteLine("Time needed: {0}\n {1} more to go......", timer.Elapsed, CountSearches - 1);
                timer.Start();
            }
        }
        timer.Stop();
        Console.WriteLine("Total search time: "+timer.Elapsed);
    }
Example #11
0
        public KinectPlayer(Vector3 platformData)
        {
            JumpLeft = false;
            progressBarBackground = new Sprite();
            progressBarBackground.Rectangle = new Rectangle(0,0,GameConstants.HorizontalGameResolution,GameConstants.VerticalGameResolution/80);
            progressBarFrame = new Sprite();
            progressBarFrame.Rectangle = new Rectangle(0,0,GameConstants.HorizontalGameResolution,GameConstants.VerticalGameResolution/80);
            newGameCounter = new Stopwatch();
            newGameCounter.Reset();

            nyanSprite = new Sprite();
            nyanSprite.Rectangle = new Rectangle(-(int)GameConstants.nyanDimensions.X, (int)GameConstants.VerticalGameResolution/25, (int)GameConstants.nyanDimensions.X, (int)GameConstants.nyanDimensions.Y);

            progressBarRectangle=new Rectangle(0,0,GameConstants.HorizontalGameResolution,GameConstants.VerticalGameResolution/80);
            progressBarTextures = new Texture2D[3];
            modelPosition = new Hero(new ObjectData3D
                                      {
                                          Scale = new Vector3(GameConstants.HeroScale),
                                          Rotation = new Vector3(0.0f)
                                      });

            currentStance = GameConstants.PlayerStance.GameSettingsSetup;
            lastStance = GameConstants.PlayerStance.GameSettingsSetup;
            isMotionCheckEnabled = true;
            modelGroundLevel = platformData.Y+GameConstants.PlayerModelHeight;
            modelPosition.objectArrangement.Position = new Vector3(platformData.X,modelGroundLevel,platformData.Z);
            modelPosition.oldArrangement = modelPosition.objectArrangement;
            currentModel = modelUp;
        }
Example #12
0
    // Use this for initialization
    void Start()
    {
        file = new System.IO.StreamWriter("K:\\Logs\\ArrayTest.txt");
        array1 = new GameObject[cycles];
        array2 = new GameObject[cycles];
        stopWatch = new Stopwatch();
        GameObject test = Instantiate(memCell, Vector3.zero, Quaternion.identity) as GameObject;
        for (int i = 0; i< cycles; i++){
            array1[i] = Instantiate(memCell, new Vector3(i,0f,0f), Quaternion.identity) as GameObject;
            array1[i].SetActive(false);
        }

        for (int i=0; i<cycles; i++){
            stopWatch.Reset ();
            stopWatch.Start();

            //write(array1[i], i);
            write(i);

            stopWatch.Stop();
            TimeSpan ts = stopWatch.Elapsed;
            file.WriteLine(ts.TotalMilliseconds + "\t");

        }
    }
Example #13
0
 public static void playGame(Game.Client client)
 {
     GameInit gameInit = client.ready();
     GameInfo gameInfo = gameInit.GameInfo;
     Solution solution = new Solution(gameInit);
     Stopwatch stopwatch = new Stopwatch();
     stopwatch.Start();
     while (true) {
         stopwatch.Stop();
         synchronize(gameInfo.NextWorldModelTimeEstimateMs - stopwatch.Elapsed.Milliseconds);
         gameInfo = client.getGameInfo();
         stopwatch.Reset();
         stopwatch.Start ();
         if (gameInfo.GameStatus == GameStatus.FINISHED)
         {
             solution.EndOfGame(gameInfo.GameResult);
             break;
         }
         if (gameInfo.IsMyTurn)
         {
             Command command = solution.playTurn(gameInfo.WorldModel, gameInfo.Cycle);
             client.sendCommand(command);
         }
     }
 }
Example #14
0
        public Civilian(Vector2 origin, Texture2D texture)
            : base(origin, texture)
        {
            lifeTime = new Stopwatch();
            lifeTime.Reset();

            this.Heading = new Vector2(0, 1);
            shot = false;
        }
    public void Should_be_fast()
    {
        var stopWatch = new Stopwatch();
        stopWatch.Start();
        for (var i = 0; i < 10000; i++)
            SaveFocusSession(i.ToString());

        Assert.That(stopWatch.Elapsed.TotalSeconds, Is.LessThan(10));
        stopWatch.Reset();

        var allSessions = LoadAllSessions.Run();
        Assert.That(stopWatch.Elapsed.Milliseconds, Is.LessThan(300));
        Assert.That(allSessions.Count, Is.EqualTo(10000));

        stopWatch.Reset();
        Console.WriteLine(allSessions.Sum(x => x.Minutes));
        Console.WriteLine(stopWatch.Elapsed);
    }
Example #16
0
    /* 3 Write a program that finds a set of words (e.g. 1000 words)
     * in a large text (e.g. 100 MB text file). Print how many times
     * each word occurs in the text.
     * Hint: you may find a C# trie in Internet.
     * */
    static void Main(string[] args)
    {
        var dict = new Dictionary<string, int>();
        var knownCount = new Dictionary<string, int>
        {
            {"foo", 10*1000},
            {"bar", 20*1000},
            {"quux",30*1000},
            {"frob",40*1000},
            {"asdf",50*1000}
        };
        var trie = new Trie<int>();

        var sw = new Stopwatch();

        sw.Start();

        // obviously, I couldn't zip the 100 MB file
        // use "bin\debug\generator.cs" to generate it if you want

        using (var reader = new StreamReader("text.txt"))
            foreach (var word in Words(reader))
                dict[word] = 1 + dict.GetOrDefault(word, 0);

        sw.Stop();
        /*
        foreach (var kvp in knownCount)
            Debug.Assert(dict[kvp.Key] == kvp.Value);
        */

        Console.WriteLine("Using hashtable: " + sw.Elapsed.TotalMilliseconds);

        sw.Reset();
        sw.Start();

        using (var reader = new StreamReader("text.txt"))
            foreach (var word in Words(reader))
                trie.Add(word, 1 + trie.GetOrDefault(word, 0));

        sw.Stop();

        foreach (var kvp in dict)
            Debug.Assert(trie.Find(kvp.Key) == kvp.Value);

        // the trie would probably do much better compared to a hashtable when used on
        // natural text with large amount of repetition and low average word length
        // it is however extremely space inefficient

        // at any rate, I'd be surprised if this implementation could beat .NET's build-in
        // hashtable

        Console.WriteLine("Using trie: " + sw.Elapsed.TotalMilliseconds);
    }
Example #17
0
 internal void LoadEntryPoints()
 {
   int num = 0;
   FieldInfo[] fields = this.DelegatesClass.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
   if (fields == null)
     throw new InvalidOperationException("The specified type does not have any loadable extensions.");
   Stopwatch stopwatch = new Stopwatch();
   stopwatch.Reset();
   stopwatch.Start();
   foreach (FieldInfo fieldInfo in fields)
   {
     Delegate @delegate = this.LoadDelegate(fieldInfo.Name, fieldInfo.FieldType);
     if (@delegate != null)
       ++num;
     lock (this.SyncRoot)
       fieldInfo.SetValue((object) null, (object) @delegate);
   }
   this.rebuildExtensionList = true;
   stopwatch.Stop();
   stopwatch.Reset();
 }
Example #18
0
 private static void stringConcat(String[] ss, int n)
 {
     // This is *very* slow for large n
     Stopwatch t = new Stopwatch();
     t.Reset();
     t.Start();
     String res = "";
     for (int i=0; i<n; i++)
       res += ss[i];
     t.Stop();
     Console.WriteLine("Result length:{0,7};    time:{1,8:F3} sec\n" ,
           res.Length, t.ElapsedMilliseconds/1000.0);
 }
    public int Receive(out string s)
    {
        s = "";

        try
        {
            if (tc.Connected == false) return 1;

            tc.ReceiveTimeout = to;
            Stream st = tc.GetStream();

            st.ReadTimeout = to;

            int len;

            do
            {
                len = st.ReadByte();
            } while (len == 0);

            Stopwatch sw = new Stopwatch();
            sw.Reset();
            //sw.Start();

            for (int i = 0; i < len && sw.ElapsedMilliseconds < to * len; i++)
            {
                int b;
                do
                {
                    b = st.ReadByte();
                }
                while (b == -1 && sw.ElapsedMilliseconds < to * len);

                s += (char)b;
            }

            sw.Stop();
            if (sw.ElapsedMilliseconds < to * len)
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }
        catch (Exception e)
        {
            return 1;
        }
    }
Example #20
0
	public int Run()
	{
		Stopwatch sw = new Stopwatch();		
		AutoResetEvent are = new AutoResetEvent(false);
		sw.Start();
		bool ret = are.WaitOne(1000);//,false);
		sw.Stop();
		//We should never get signaled
		if(ret)
		{
			Console.WriteLine("AutoResetEvent should never be signalled.");
			return -1;
		}

		if(sw.ElapsedMilliseconds < 900)
		{
			Console.WriteLine("It should take at least 900 milliseconds to call bool ret = are.WaitOne(1000,false);.");
			Console.WriteLine("sw.ElapsedMilliseconds = " + sw.ElapsedMilliseconds);			
			return -2;
		}
		
		are.Set();
		if(!are.WaitOne(0))//,false))
		{
			Console.WriteLine("Signalled event should always return true on call to !are.WaitOne(0,false).");
			return -3;
		}
		
		sw.Reset();		
		sw.Start();
		ret = are.WaitOne(1000);//,false);
		sw.Stop();
		//We should never get signaled
		if(ret)
		{
			Console.WriteLine("AutoResetEvent should never be signalled after is is AutoReset.");
			return -4;
		}

		if(sw.ElapsedMilliseconds < 900)
		{
			Console.WriteLine("It should take at least 900 milliseconds to call bool ret = are.WaitOne(1000,false);.");
			Console.WriteLine("sw.ElapsedMilliseconds = " + sw.ElapsedMilliseconds);			
			return -5;
		}
		
		return 100;
		
	}
Example #21
0
    static void Main()
    {
        string fileLocation = "@../../text.txt";
        StreamReader reader = new StreamReader(fileLocation);
        string text;

        using(reader)
        {
            text = reader.ReadToEnd();
        }

        char[] separators = new char[] { '.', ',', ' ', '?', '!', '-', '(', ')' };

        string[] words = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);

        WordsTree tree = new WordsTree();
        Dictionary<string, int> dict = new Dictionary<string, int>();

        Stopwatch watch = new Stopwatch();
        watch.Start();

        foreach (var word in words)
        {
            tree.Add(word);
        }

        Console.WriteLine(tree.SearchOccurences("sit"));
        watch.Stop();
        Console.WriteLine("Time elapsed trie structure: {0}", watch.Elapsed);

        watch.Reset();
        watch.Start();

        foreach (var word in words)
        {
            if (dict.ContainsKey(word))
            {
                dict[word]++;
            }
            else
            {
                dict.Add(word, 1);
            }
        }

        Console.WriteLine(dict["sit"]);
        watch.Stop();
        Console.WriteLine("Time elapsed dictionary: {0}", watch.Elapsed);
    }
Example #22
0
 private static void stringBuilder(String[] ss, int n)
 {
     // This is fast for all n
     Stopwatch t = new Stopwatch();
     t.Reset();
     t.Start();
     String res = null;
     StringBuilder buf = new StringBuilder();
     for (int i=0; i<n; i++)
       buf.Append(ss[i]);
     res = buf.ToString();
     t.Stop();
     Console.WriteLine("Result length:{0,7};    time:{1,8:F3} sec\n" ,
           res.Length, t.ElapsedMilliseconds/1000);
 }
Example #23
0
    private void Start()
    {
        //yield return new WaitForSeconds(0.1f);
        if(SVGFile != null) {
          Stopwatch w = new Stopwatch();

          w.Reset();
          w.Start();
          ISVGDevice device;
          if(fastRenderer)
        device = new SVGDeviceFast();
          else
        device = new SVGDeviceSmall();
          var implement = new Implement(SVGFile, device);
          w.Stop();
          long c = w.ElapsedMilliseconds;

          w.Reset();
          w.Start();
          implement.StartProcess();
          w.Stop();
          long p = w.ElapsedMilliseconds;

          w.Reset();
          w.Start();
          var myRenderer = GetComponent<Renderer>();
          var result = implement.GetTexture();
          result.wrapMode   = wrapMode;
          result.filterMode = filterMode;
          result.anisoLevel = anisoLevel;
          myRenderer.material.mainTexture = result;
          w.Stop();
          long r = w.ElapsedMilliseconds;
          UnityEngine.Debug.LogFormat("Construction: {0} ms, Processing: {1} ms, Rendering: {2} ms", c, p, r);
        }
    }
Example #24
0
	static void Main()
	{
		var stopwatch = new Stopwatch(); // создаем таймер
		stopwatch.Reset();               // так делается сброс таймера
		stopwatch.Start();               // запускаем таймер
		
		double id, i = 100;                         // функции, время выполнения...
		for (id = 0;id<i;id++) Console.WriteLine(id); // ...которых мы хотим измерить
		
		stopwatch.Stop(); // остановка таймера
		Console.WriteLine(); // далее вывод результатов...
		Console.WriteLine("Тактов:\t{0:###,###,###}", stopwatch.ElapsedTicks       );
		Console.WriteLine("Мс:    \t{0:###,###}"    , stopwatch.ElapsedMilliseconds);
		
		Console.ReadKey();
	}
        public Mediator_Player_Controls(Controls c_, H_Player p_)
        {
            p_avatar = p_;
            c_input = c_;
            shooter = Shoot_State.CHILL;
            jumper = Jump_State.ON_GROUND;
            AirTime = new Stopwatch();
            AirTime.Reset();
            AirTime.Stop();

            cur_structure = 0;
            structure_wheel.Add(Structure_Type_e.HEALING_POOL);
            structure_wheel.Add(Structure_Type_e.SNOW_FACTORY);
            structure_wheel.Add(Structure_Type_e.FORT);
            structure_wheel.Add(Structure_Type_e.SNOWMAN);
        }
    //Decimal operations
    private static TimeSpan MesurePerformanceOfDecimalOperations(decimal numOne, decimal numTwo, string sign, Stopwatch stoplatch)
    {
        stoplatch.Reset();
        decimal sum = 0;

        switch (sign)
        {
            case "+":
                {
                    stoplatch.Start();
                    sum = numOne + numTwo;
                    stoplatch.Stop();
                    return stoplatch.Elapsed;
                }
            case "-":
                {
                    stoplatch.Start();
                    sum = numOne - numTwo;
                    stoplatch.Stop();
                    return stoplatch.Elapsed;
                }
            case "++":
                {
                    stoplatch.Start();
                    numOne++;
                    stoplatch.Stop();
                    return stoplatch.Elapsed;
                }
            case "*":
                {
                    stoplatch.Start();
                    sum = numOne * numTwo * 555555555;
                    stoplatch.Stop();
                    return stoplatch.Elapsed;
                }
            case "/":
                {
                    stoplatch.Start();
                    sum = numOne / numTwo;
                    stoplatch.Stop();
                    return stoplatch.Elapsed;
                }
            default:
                throw new ArgumentException("This is not a valid sign");
        }
    }
Example #27
0
    public static void Main()
    {
        List<long> times = new List<long>();
        var stopwatch = new Stopwatch();
        for (int i = 0; i < 5; i++)
        {
            stopwatch.Start();
            List<int> result = PrimesUnder(3000000);
            stopwatch.Stop();

            times.Add(stopwatch.ElapsedMilliseconds);
            stopwatch.Reset();
        }

        foreach (var time in times)
            Console.WriteLine(time);
    }
Example #28
0
    /* Task 2:
     * Write a program to read a large collection of products (name + price) I love 
     * and efficiently find the first 20 products in the price range [a…b]. Test for 
     * 500 000 products and 10 000 price searches.
     * Hint: you may use OrderedBag<T> and sub-ranges.
     */

    static void Main(string[] args)
    {
        Random randomGenerator = new Random();
        Stopwatch stopWatch = new Stopwatch();

        string[] product = { "bread", "butter", "meat", "eggs", "flower", "oil", "soda", "candy" };
        var productLenght = product.Length;
        var orderedDictionary = new OrderedDictionary<int, string>();

        stopWatch.Start();
        while (orderedDictionary.Count < 500000)
        {
            var key = randomGenerator.Next(1, 1000000);
            var value = product[randomGenerator.Next(0, productLenght)];
            if (!orderedDictionary.ContainsKey(key))
            {
                orderedDictionary.Add(key, value);
            }
        }

        stopWatch.Stop();

        Console.WriteLine("Time for creating the elements is: {0}", stopWatch.Elapsed);

        stopWatch.Reset();

        stopWatch.Start();
        for (int i = 0; i < 10000; i++)
        {
            var min = randomGenerator.Next(0, 500000);
            var max = randomGenerator.Next(500000, 1000000);
            var products = orderedDictionary.Range(min, true, max, true);
        }
        stopWatch.Stop();

        Console.WriteLine("Time for performing 10k range searches: {0}", stopWatch.Elapsed);

        var range = orderedDictionary.Range(1000, true, 100000, true);

        for (int i = 0; i < 20; i++)
        {
            Console.WriteLine(range.ElementAt(i));
        }
    }
Example #29
0
	static void Main(string[] args){
		int n = 1;
		int count = 0;
		Random rnd = new Random (42);
		Stopwatch st = new Stopwatch ();
		if (args.Length > 0) n = Int32.Parse(args[0]);

		int[] v = new int [n];
		for (int i = 0; i < n; i++)
			v [i] = i;

		/* Shuffle */
		for (int i = n - 1; i > 0; i--) {
			int t, pos;
			pos = rnd.Next () % i;
			t = v [i];
			v [i] = v [pos];
			v [pos] = t;
		}

		Hashtable table = new Hashtable (n); 

		st.Start ();
		for (int i = 0; i < n; i++) 
			table.Add (v [i], v [i]);
		for (int i = 0; i < n; i++) 
			table.Remove (v [i]);
		for (int i = n - 1; i >= 0; i--) 
			table.Add (v [i], v [i]);
		st.Stop ();  
		Console.WriteLine ("Addition {0}", st.ElapsedMilliseconds);

		st.Reset ();
		st.Start ();
		for (int j = 0; j < 8; j++) {
			for (int i = 0; i < n; i++) {
				if (table.ContainsKey (v [i]))
					count++;
			}	
		}
		st.Stop ();
		Console.WriteLine ("Lookup {0} - Count {1}", st.ElapsedMilliseconds, count);

	}
Example #30
0
 // Use this for initialization
 void Start()
 {
     var watch = new Stopwatch();
     watch.Start();
     for(var i = 0; i < 10000; i ++)
     {
     //			var t = transform.position;
     }
     watch.Stop();
     UnityEngine.Debug.Log(watch.ElapsedTicks/10000000f);
     watch.Reset();
     watch.Start();
     for(var i = 0; i < 10000; i ++)
     {
     //		var t = transform.localPosition;
     }
     watch.Stop();
     UnityEngine.Debug.Log(watch.ElapsedTicks/10000000f);
 }