public unsafe void TestRandom(int count)
        {
            int loopCount = 200;

            uint[] items      = new uint[count];
            uint[] lookupList = new uint[count];

            for (uint x = 0; x < items.Length; x++)
            {
                items[x]      = 2 * x;
                lookupList[x] = 2 * x + 1;
            }
            Shuffle(lookupList, 3, 10);

            StepTimer.Reset();
            for (int cnt = 0; cnt < loopCount; cnt++)
            {
                //GC.Collect(0);

                //items = (uint[])items.Clone();

                //GC.WaitForPendingFinalizers();
                //System.Threading.Thread.Sleep(10);

                SnapCustomMethodsUInt32 bin = new SnapCustomMethodsUInt32();
                fixed(uint *lp = items)
                {
                    byte *     lpp = (byte *)lp;
                    SnapUInt32 box = new SnapUInt32();

                    StepTimer.ITimer timer = StepTimer.Start("Lookup");
                    for (int x = 0; x < lookupList.Length; x++)
                    {
                        box.Value = lookupList[x];
                        bin.BinarySearch(lpp, box, count, 4);
                        //BoxKeyMethodsUint32.BinarySearchTest(lpp, box, count, 4);
                    }
                    timer.Stop();
                }
            }

            StringBuilder SB = new StringBuilder();

            //Console.Write(count.ToString("Tree\t0\t"));
            //SB.Append((count * 4).ToString("0\t") + (count / StepTimer.GetAverage("Lookup") / 1000000).ToString("0.000\t"));
            //SB.Append((count * 4.0 / 1024).ToString("0.###\t") + ((StepTimer.GetAverage("Lookup") / Math.Log(count, 2)) / count * 1000000000).ToString("0.00\t"));
            SB.Append(((StepTimer.GetSlowest("Lookup") / Math.Log(count, 2)) / count * 1000000000).ToString("0.00\t"));
            //SB.Append(((StepTimer.GetAverage("Lookup") / Math.Log(count, 2)) / count * 1000000000).ToString("0.00\t"));
            Console.WriteLine(SB.ToString());
        }
Example #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     Clipboard.SetText(StepTimer.GetResultsPercent());
     StepTimer.Reset();
 }
Example #3
0
 public void Update(GameTime time)
 {
     if (KeyboardHelper.KeyPressed(Keys.Escape))
     {
         paused = !paused;
         if (paused)
         {
             return;
         }
     }
     heatMap.UpdateBegin(time);
     winTimer.Update(time);
     fireSndTimer.Update(time);
     fireExtSndTimer.Update(time);
     if (winTimer.HasTick())
     {
         if (game.LevelSelectScreen.Progress < levelId)
         {
             game.LevelSelectScreen.Progress = levelId;
         }
         game.ChangeScreen(game.LevelEndScreen.SetWin(true));
     }
     else if (gameObjectInstances.Where(inst => !inst.IsDestroyed).Sum(inst => inst.Type.Cost) < startingCost / 3 || player.IsDead)
     {
         game.ChangeScreen(game.LevelEndScreen.SetWin(false));
     }
     foreach (var inst in gameObjectInstances)
     {
         inst.Update(time, heatMap, partSystem, this);
     }
     foreach (var inst in gameObjectInstances)
     {
         inst.UpdateFromHeatmap(heatMap);
     }
     partSystem.Update(time);
     foreach (var agent in partSystem.GetAgents())
     {
         var c = agent.CollisionMask;
         foreach (var inst in gameObjectInstances)
         {
             if (inst.IsBurning && inst.CollidesWith(c))
             {
                 inst.Extinguish(agent.Type);
             }
         }
         heatMap.CoolDown(new Point(c.X, c.Y));
         if (wallColliders.Any(w => w.CollidesWith(c)))
         {
             agent.Kill();
         }
     }
     player.Update(time, heatMap, partSystem);
     if (gameObjectInstances.Any(inst => inst.IsBurning))
     {
         winTimer.Reset();
     }
     if (fireSndTimer.HasTick())
     {
         var b = Math.Min(2000f, gameObjectInstances.Sum(inst => inst.Burning));
         if (b > 0)
         {
             FireSound.Play(b / 2000f, 0f, 0f);
         }
     }
     fireSndTimer.TakeTicks();
     fireExtSndTimer.TakeTicks();
 }