示例#1
0
        public override bool PayTask(string sender, out string transactionId, out bool hasFunds)
        {
            Watch.Start();
            transactionId = null;
            hasFunds      = false;
            IncentiveAssigned incentiveAssigned;

            try
            {
                incentiveAssigned = this.Incentive.CreateTaskIncentive();

                //register the transaction
                log.DebugFormat("User: [{0}] going to pay [{1}] to create a Task", sender, incentiveAssigned.IncentiveQty);
                RegisterTransaction(sender, this.ManagerAddress, incentiveAssigned, out transactionId, out hasFunds);
                Watch.Stop();
                Log.DebugFormat("Execution Time on IncentiveEngineNode Decentralized: [{0}] milliseconds to Pay Task", Watch.ElapsedMilliseconds);
                Watch.Reset();
                return(true);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                return(false);
            }
        }
示例#2
0
        public override bool RewardUser(string receiver, IncentiveAssigned incentiveAssigned, out object reward, out string transactionId)
        {
            Watch.Start();
            reward        = null;
            transactionId = null;
            bool hasFunds = false;

            try
            {
                //obtain the reward for completing the task
                incentiveAssigned = Incentive.CompleteTaskIncentive();

                //create the transaction and store it into the TransactionStorage
                if (!RegisterTransaction(this.ManagerAddress, receiver, incentiveAssigned, out transactionId, out hasFunds))
                {
                    return(false);
                }
                reward = new Dictionary <string, string>()
                {
                    { "quantity", incentiveAssigned.IncentiveQty.ToString() },
                    { "incentive", incentiveAssigned.IncentiveName }
                };
                Watch.Stop();
                Log.DebugFormat("Execution Time on IncentiveEngineNode Centralized: [{0}] milliseconds to Reward User", Watch.ElapsedMilliseconds);
                Watch.Reset();
                return(true);
            }
            catch (Exception ex)
            {
                log.ErrorFormat(ex.Message);
                return(false);
            }
        }
        protected void CompareSearch(List <MockItem> list, OptimizedCollection <MockItem> collection)
        {
            int key = new Random(new Random().Next(0, list.Count - 1)).Next(0, list.Count - 1);

            Watch.Reset();
            var query =
                collection.Using <UniqueKeyQuery <MockItem, int> >();

            Watch.Start();

            var mockedInCollection = query.Get(key);

            Watch.Stop();

            var elapsed4Collection = Watch.Elapsed;

            Watch.Reset();
            Watch.Start();
            var mockedInList = list.BinarySearch(new MockItem {
                Index = key
            });

            Watch.Stop();

            var elapsed4List = Watch.Elapsed;


            Console.WriteLine("For the list<T>, took {0} to get one item, \n FastLane took {1}.",
                              elapsed4List, elapsed4Collection);
        }
示例#4
0
        public override void UpdateBeforeSimulation()
        {
            Watch.Start();
            Aux(ticks: 1);
            Ticks += 1;
            InventoryUpdateTicks += 1;
            if (Ticks >= SessionCore.WorkSkipTicks)
            {
                Ticks = 0;
                Main(ticks: SessionCore.WorkSkipTicks);
            }
            if (Tool is IMyShipWelder && InventoryUpdateTicks >= SessionCore.InventoryRebuildSkipTicks)
            {
                InventoryUpdateTicks = 0;
                BuildInventoryCache();
            }

            Watch.Stop();
            if (LastRunTimes.Count >= RunTimeCacheSize)
            {
                LastRunTimes.Dequeue();
            }
            LastRunTimes.Enqueue(1000 * (Watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency));
            Watch.Reset();
        }
示例#5
0
        public override bool PayTask(string sender, out string transactionId, out bool hasFunds)
        {
            Watch.Start();
            transactionId = null;
            IncentiveAssigned incentiveAssigned;

            hasFunds = false;

            try
            {
                incentiveAssigned = Incentive.CreateTaskIncentive();

                //create the transaction and store it into the TransactionStorage
                log.DebugFormat("User: [{0}] going to pay [{1}] to create a Task", sender, incentiveAssigned.IncentiveQty);
                if (!RegisterTransaction(sender, this.ManagerAddress, incentiveAssigned, out transactionId, out hasFunds))
                {
                    Console.WriteLine("[ERROR - INCENTIVE ENGINE] - Cannot register task payment!");
                    return(false);
                }
                Watch.Stop();
                Log.DebugFormat("Execution Time on IncentiveEngineNode Centralized: [{0}] milliseconds to Pay Task", Watch.ElapsedMilliseconds);
                Watch.Reset();
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#6
0
        public override long GetPerformanceToSearch()
        {
            queue = (Queue <object>)Data.ListObject.Find(item => item is Queue <object>);

            Watch.Reset();
            Watch.Start();

            var result = queue.ToArray().Where(item => item.Equals(Data.ForSearch));

            Watch.Stop();

            return(Watch.ElapsedMilliseconds);
        }
示例#7
0
        public override long GetPerformanceToClear()
        {
            arrayList = (ArrayList)Data.GetValue().Find(item => item is ArrayList);

            Watch.Reset();
            Watch.Start();

            arrayList.RemoveRange(0, CalculateArrayList.CountOfObject);

            Watch.Stop();

            return(Watch.ElapsedMilliseconds);
        }
 public void PregameReset()
 {
     GoalsList.Items.Clear();
     TimeBtn.IsEnabled            = true;
     RobotSetToggle.IsChecked     = false;
     ToteSetToggle.IsChecked      = false;
     ContainerSetToggle.IsChecked = false;
     Time = TimeSpan.Zero;
     Watch.Reset();
     TimeBar.Value = 0;
     UnprocessedLitterCount.Text = "0";
     SaveBtn.IsEnabled           = false;
     TimeBar.Foreground          = new SolidColorBrush(AUTO_COLOR);
 }
示例#9
0
        public override long GetPerformanceToSearch()
        {
            arrayList = (ArrayList)Data.ListObject.Find(item => item is ArrayList);

            Watch.Reset();
            Watch.Start();

            var index  = arrayList.IndexOf(Data.ForSearch);
            var result = arrayList[index];

            Watch.Stop();

            return(Watch.ElapsedMilliseconds);
        }
示例#10
0
        public override long GetPerformanceToSearch()
        {
            linkedList = (LinkedList <object>)Data.ListObject.Find(item => item is LinkedList <object>);

            Watch.Reset();
            Watch.Start();

            var node   = linkedList.Find(Data.ForSearch);
            var result = node.Value;

            Watch.Stop();

            return(Watch.ElapsedMilliseconds);
        }
示例#11
0
        public override long GetPerformanceToSearch()
        {
            dictionary = (Dictionary <int, object>)Data.ListObject.Find(item => item is Dictionary <int, object>);

            Watch.Reset();
            Watch.Start();

            var result = dictionary.Values
                         .ToList()
                         .Where(item => item.Equals(Data.ForSearch));

            Watch.Stop();

            return(Watch.ElapsedMilliseconds);
        }
示例#12
0
        public override long GetPerformanceToClear()
        {
            dictionary = (Dictionary <int, object>)Data.GetValue().Find(item => item is Dictionary <int, object>);

            Watch.Reset();
            Watch.Start();

            for (var i = 0; i < Calculate.CountOfObject; i++)
            {
                dictionary.Remove(i);
            }

            Watch.Stop();

            return(Calculate.GetResultWithoutOverhead());
        }
示例#13
0
        public override long GetPerformanceToAdd()
        {
            Watch.Reset();
            Watch.Start();

            for (var i = 0; i < Calculate.CountOfObject; i++)
            {
                linkedList.AddLast(new object());
            }

            Watch.Stop();

            linkedList.Clear();

            return(Calculate.GetResultWithoutOverhead());
        }
示例#14
0
        public override long GetPerformanceToClear()
        {
            linkedList = (LinkedList <object>)Data.GetValue().Find(item => item is LinkedList <object>);

            Watch.Reset();
            Watch.Start();

            for (var i = 0; i < Calculate.CountOfObject; i++)
            {
                linkedList.RemoveLast();
            }

            Watch.Stop();

            return(Calculate.GetResultWithoutOverhead());
        }
示例#15
0
        public override long GetPerformanceToClear()
        {
            hashtable = (Hashtable)Data.GetValue().Find(item => item is Hashtable);

            Watch.Reset();
            Watch.Start();

            for (var i = 0; i < Calculate.CountOfObject; i++)
            {
                hashtable.Remove(i);
            }

            Watch.Stop();

            return(Calculate.GetResultWithoutOverhead());
        }
示例#16
0
        public override long GetPerformanceToSearch()
        {
            hashtable = (Hashtable)Data.ListObject.Find(item => item is Hashtable);

            Watch.Reset();
            Watch.Start();

            var result = hashtable.Values
                         .OfType <string>()
                         .ToList()
                         .Where(item => item.Equals(Data.ForSearch));

            Watch.Stop();

            return(Watch.ElapsedMilliseconds);
        }
示例#17
0
        public override long GetPerformanceToClear()
        {
            queue = (Queue <object>)Data.GetValue().Find(item => item is Queue <object>);

            Watch.Reset();
            Watch.Start();

            for (var i = 0; i < Calculate.CountOfObject; i++)
            {
                queue.Dequeue();
            }

            Watch.Stop();

            return(Calculate.GetResultWithoutOverhead());
        }
示例#18
0
        public override long GetPerformanceToAdd()
        {
            Watch.Reset();
            Watch.Start();

            for (var i = 0; i < Calculate.CountOfObject; i++)
            {
                hashtable.Add(i, new object());
            }

            Watch.Stop();

            hashtable.Clear();

            return(Calculate.GetResultWithoutOverhead());
        }
示例#19
0
        protected void CompareSearch(List <MockItem> list, OptimizedCollection <MockItem> collection)
        {
            var max = list.Count;

            Watch.Reset();

            var query =
                collection.Using <UniqueKeyQuery <MockItem, int> >();

            Watch.Start();

            for (int i = 0; i < max; i++)
            {
                var mockedInCollection = query.Get(i);
            }
            Watch.Stop();

            var elapsed4Collection = Watch.Elapsed;

            Watch.Reset();
            Watch.Start();
            for (int i = 0; i < max; i++)
            {
                var mockedInList = list.BinarySearch(new MockItem {
                    Index = i
                });
            }
            Watch.Stop();

            var elapsed4List = Watch.Elapsed;

            //Watch.Reset();
            //Watch.Start();
            //for (int i = 0; i < max; i++)
            //{
            //    var mockedInList = list.FirstOrDefault(item => item.Index == i);
            //}
            //Watch.Stop();

            var elapsed4ListLinq = Watch.Elapsed;

            Console.WriteLine("For the list<T>, took {0} to get all items, for FastLane took {1}.",
                              elapsed4List, elapsed4Collection);

            //Console.WriteLine("For the list<T> with linq, took {0} to get all items, for FastLane took {1}.",
            //    elapsed4ListLinq, elapsed4Collection);
        }
        protected void CompareSearch(List <MockItem> list, OptimizedCollection <MockItem> collection)
        {
            var max = list.Count;

            Watch.Reset();

            var query =
                collection.Using <_Query>();

            Watch.Start();

            for (int i = 0; i < max; i++)
            {
                var mockedInCollection = query.Get(BitConverter.GetBytes(i));
            }
            Watch.Stop();

            var elapsed4Collection = Watch.Elapsed;

            Watch.Reset();
            Watch.Start();
            for (int i = 0; i < max; i++)
            {
                var mockedInList = list.BinarySearch(new MockItem {
                    Index = i
                });
            }
            Watch.Stop();

            var elapsed4List = Watch.Elapsed;

            Watch.Reset();
            Watch.Start();
            for (int i = 0; i < max; i++)
            {
                var mockedInList = list.First(item => item.Index == i);
            }
            Watch.Stop();

            var elapsed4ListLinq = Watch.Elapsed;

            Console.WriteLine("For the list<T>, took {0} to get all items, for FastLane took {1}.",
                              elapsed4List, elapsed4Collection);

            Console.WriteLine("For the list<T> with linq, took {0} to get all items, for FastLane took {1}.",
                              elapsed4ListLinq, elapsed4Collection);
        }
示例#21
0
        public override bool RewardUser(string receiver, IncentiveAssigned incentiveAssigned, out object reward, out string transactionId)
        {
            Watch.Start();
            List <string> userNodes;

            reward        = null;
            transactionId = null;
            bool hasFunds;

            try
            {
                userNodes = this.Repository.GetUserMultichainNodes(receiver);

                if (userNodes != null)
                {
                    //increase the incentive based on the number of nodes contributing to the blockchain
                    if (userNodes.Count != 0)
                    {
                        incentiveAssigned.IncentiveQty *= userNodes.Count;
                    }
                }
                else
                {
                    return(false);
                }
                //transfer the incentive to the user
                if (!RegisterTransaction(ManagerAddress, receiver, incentiveAssigned, out transactionId, out hasFunds))
                {
                    return(false);
                }
                reward = new Dictionary <string, string>()
                {
                    { "quantity", incentiveAssigned.IncentiveQty.ToString() },
                    { "incentive", incentiveAssigned.IncentiveName }
                };
                Watch.Stop();
                Log.DebugFormat("Execution Time on IncentiveEngineNode Decentralized: [{0}] milliseconds to Reward User", Watch.ElapsedMilliseconds);
                Watch.Reset();
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#22
0
        protected void CompareSearch(SortedList <int, MockItem> list, OptimizedCollection <MockItem> collection)
        {
            var max = list.Count;

            Watch.Reset();
            int i = 0;

            Watch.Start();
            try
            {
                for (i = 1; i < max; i++)
                {
                    var mockedInList = list[i];
                }
            }
            catch
            {
                Console.WriteLine("index " + i);
            }
            Watch.Stop();

            var elapsed4List = Watch.Elapsed;

            Watch.Reset();

            var query =
                collection.Using <UniqueKeyQuery <MockItem, int> >();

            Watch.Start();

            for (i = 0; i < max; i++)
            {
                var mockedInCollection =
                    query.Get(i);
            }
            Watch.Stop();

            var elapsed4Collection = Watch.Elapsed;

            Console.WriteLine("For the SortedList<int, T>, took {0} to get one item, for FastLane took {1}.",
                              elapsed4List, elapsed4Collection);
        }
示例#23
0
        /// <summary>
        /// Called when it is time to draw a frame.
        /// </summary>
        public override void Draw()
        {
            // Clears the background
            Display.ClearBuffers();


            string msg = "empty";

            if (Keyboard.IsKeyPress(Keys.D))
            {
                msg = "Immediate mode";
                Sprite.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, false);
            }
            else
            {
                msg = "Texture sort mode";
                Sprite.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Texture, false);
            }

            Watch.Reset();
            Watch.Start();
            foreach (Particle particle in Particles)
            {
                Sprite.Draw(particle.Texture, particle.Location, Color.FromArgb(particle.Alpha, particle.Color));
            }
            Watch.Stop();
            Sprite.End();


            // Some blah blah...
            Sprite.Begin();
            Sprite.DrawString(Font, new Vector2(10, 220), Color.White, "BatchCall : {0}", Display.Statistics.BatchCall);
            Sprite.DrawString(Font, new Vector2(10, 100), Color.White, msg);
            Sprite.DrawString(Font, new Vector2(10, 180), Color.White, "Press 'D' key for direct mode");
            Sprite.DrawString(Font, new Vector2(10, 200), Color.White, "Shader binding : {0}", Display.Statistics.ShaderBinding);
            Sprite.DrawString(Font, new Vector2(10, 240), Color.White, "TextureBinding {0}", Display.Statistics.TextureBinding);
            Sprite.DrawString(Font, new Vector2(10, 260), Color.White, "Elapsed time : {0} ms", Watch.ElapsedMilliseconds);
            Sprite.End();
        }
        protected void CompareSearch(SortedList <int, MockItem> list, OptimizedCollection <MockItem> collection)
        {
            int key = new Random(new Random().Next(0, list.Count - 1)).Next(0, list.Count - 1);

            Watch.Reset();
            Watch.Start();
            var mockedInList = list[key];

            Watch.Stop();

            var elapsed4List = Watch.Elapsed;

            Watch.Reset();
            Watch.Start();
            var mockedInCollection =
                collection.Using <UniqueKeyQuery <MockItem, int> >().Get(key);

            Watch.Stop();

            var elapsed4Collection = Watch.Elapsed;

            Console.WriteLine("For the SortedList<int, T>, took {0} to get one item, for FastLane took {1}.",
                              elapsed4List, elapsed4Collection);
        }
示例#25
0
 public ProfileRegion()
 {
     _currentRegion = this;
     Watch.Reset();
     Watch.Start();
 }
示例#26
0
文件: StopWatch.cs 项目: lichange/NS
 /// <summary>
 /// 重置计时器
 /// </summary>
 public virtual void Reset()
 {
     Watch.Reset();
 }
示例#27
0
 public void Start()
 {
     Watch.Reset();
     Watch.Start();
 }
示例#28
0
 private void btnReset_Click(object sender, EventArgs e)
 {
     watch.Reset();
 }