Пример #1
0
        public void PerformanceTest()
        {
            PerformanceTimer aTimer = new PerformanceTimer();

            ManualResetEvent aCompleted = new ManualResetEvent(false);
            object           aLock      = new object();
            int aSum = 0;


            // Using synchronized keyword
            aTimer.Start();

            for (int i = 0; i < 10; ++i)
            {
                ThreadPool.QueueUserWorkItem(x =>
                {
                    for (int j = 0; j < 1000000; ++j)
                    {
                        lock (aLock)
                        {
                            ++aSum;
                            if (aSum == 10000000)
                            {
                                aCompleted.Set();
                            }
                        }
                    }
                });
            }

            aCompleted.WaitOne();
            aTimer.Stop();

            // Using ThreadLock
            aCompleted.Reset();
            aTimer.Start();
            aSum = 0;

            for (int i = 0; i < 10; ++i)
            {
                ThreadPool.QueueUserWorkItem(x =>
                {
                    for (int j = 0; j < 1000000; ++j)
                    {
                        using (ThreadLock.Lock(aLock))
                        {
                            ++aSum;
                            if (aSum == 10000000)
                            {
                                aCompleted.Set();
                            }
                        }
                    }
                });
            }

            aCompleted.WaitOne();
            aTimer.Stop();
        }
Пример #2
0
        static void Main(string[] args)
        {
            int[]            t1    = { 1, 2, 3, 4, 5 };
            int[]            t2    = { 4, 5, 6, 7, 8 };
            PerformanceTimer timer = new PerformanceTimer();

            timer.Start();
            Compare(t1, t2);
            timer.Stop();
            Console.Write("{0}", timer.Duration);

            PerformanceTimer timer2 = new PerformanceTimer();

            timer2.Start();
            var count = Compare(t1, t2, out int[] res);

            if (count > 0)
            {
                foreach (var n in res)
                {
                    Console.Write(n + " ");
                }
            }
            timer2.Stop();
            Console.Write("{0}", timer2.Duration);

            Console.Read();
        }
Пример #3
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 10 - Puzzle A ---");
            Console.WriteLine();

            // Prompt for input.
            Console.Write("Enter number of elements: ");
            int numberOfElements = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter puzzle input: ");
            string lengths = Console.ReadLine();

            PerformanceTimer.Start();

            int result = PuzzleA.HashGenerator.GenerateHashFromLengths(
                numberOfElements,
                lengths);

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #4
0
        private static void MapCircuitBreakerStatusOutput(Output output)
        {
            Dictionary <string, OutputMeasurement> circuitBreakerStatuses = new Dictionary <string, OutputMeasurement>();

            foreach (OutputMeasurement measurement in m_network.Model.CircuitBreakerStatusOutput)
            {
                if (!circuitBreakerStatuses.ContainsKey(measurement.Key))
                {
                    circuitBreakerStatuses.Add(measurement.Key, measurement);
                }
            }

            PerformanceTimer.Reset();
            PerformanceTimer.Start();
            for (int i = 0; i < output.OutputMeta.CircuitBreakerStatuses.Length; i++)
            {
                string            key    = output.OutputMeta.CircuitBreakerStatuses[i].ID.ToString();
                OutputMeasurement status = null;
                circuitBreakerStatuses.TryGetValue(key, out status);
                if (status != null)
                {
                    output.OutputData.CircuitBreakerStatuses[i] = status.Value;
                }
            }
            PerformanceTimer.Stop();
            m_network.PerformanceMetrics.OutputPreparationExecutionTime += PerformanceTimer.ElapsedTicks;
        }
Пример #5
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 15 - Puzzle B ---");
            Console.WriteLine();

            // Prompt for input.
            Console.Write("Enter Generator A Start Value: ");
            int generatorAStartValue = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter Generator B Start Value: ");
            int generatorBStartValue = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter Number of Iterations: ");
            int numberOfIterations = Convert.ToInt32(Console.ReadLine());

            PerformanceTimer.Start();

            int result = PuzzleB.GeneratorJudge.JudgeGenerators(
                generatorAStartValue,
                generatorBStartValue,
                numberOfIterations);

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #6
0
        private static void MapCurrentFlowResidualOutput(Output output)
        {
            Dictionary <string, OutputMeasurement> currentFlowResiduals = m_network.Model.CurrentResidualOutput.ToDictionary(x => x.Key, x => x);

            PerformanceTimer.Reset();
            PerformanceTimer.Start();
            for (int i = 0; i < output.OutputMeta.CurrentFlowMagnitudeResiduals.Length; i++)
            {
                string            magnitudeKey = output.OutputMeta.CurrentFlowMagnitudeResiduals[i].ID.ToString();
                OutputMeasurement magnitude    = null;
                currentFlowResiduals.TryGetValue(magnitudeKey, out magnitude);
                if (magnitude != null)
                {
                    output.OutputData.CurrentFlowMagnitudeResiduals[i] = magnitude.Value;
                }

                string            angleKey = output.OutputMeta.CurrentFlowAngleResiduals[i].ID.ToString();
                OutputMeasurement angle    = null;
                currentFlowResiduals.TryGetValue(angleKey, out angle);
                if (angle != null)
                {
                    output.OutputData.CurrentFlowAngleResiduals[i] = angle.Value;
                }
            }
            PerformanceTimer.Stop();
            m_network.PerformanceMetrics.OutputPreparationExecutionTime += PerformanceTimer.ElapsedTicks;
        }
Пример #7
0
        private void SendOfflineBroadcastResponseMessage(string channelId, object broadcastMessage,
                                                         int numberOfClients, int numberOfMessages,
                                                         int openConnectionTimeout,
                                                         int allMessagesReceivedTimeout)
        {
            ThreadPool.SetMinThreads(50, 2);

            ClientMockFarm aClientFarm = new ClientMockFarm(MessagingSystem, channelId, numberOfClients);
            ServiceMock    aService    = new ServiceMock(MessagingSystem, channelId);

            try
            {
                aService.InputChannel.StartListening();

                // Send broadcasts.
                for (int i = 0; i < numberOfMessages; ++i)
                {
                    aService.InputChannel.SendResponseMessage("*", broadcastMessage);
                }

                Thread.Sleep(500);

                aClientFarm.OpenConnectionsAsync();

                aClientFarm.WaitUntilAllConnectionsAreOpen(openConnectionTimeout);
                aService.WaitUntilResponseReceiversConnectNotified(numberOfClients, openConnectionTimeout);
                Assert.AreEqual(aClientFarm.Clients.Count(), aService.ConnectedResponseReceivers.Count());
                foreach (ClientMock aClient in aClientFarm.Clients)
                {
                    Assert.IsTrue(aService.ConnectedResponseReceivers.Any(x => x.ResponseReceiverId == aClient.OutputChannel.ResponseReceiverId));
                }

                PerformanceTimer aStopWatch = new PerformanceTimer();
                aStopWatch.Start();

                aClientFarm.WaitUntilAllResponsesAreReceived(numberOfMessages, allMessagesReceivedTimeout);

                aStopWatch.Stop();

                foreach (DuplexChannelMessageEventArgs aResponseMessage in aClientFarm.ReceivedResponses)
                {
                    Assert.AreEqual(broadcastMessage, aResponseMessage.Message);
                }
            }
            finally
            {
                EneterTrace.Debug("CLEANING AFTER TEST");

                aClientFarm.CloseAllConnections();
                aService.InputChannel.StopListening();

                //EneterTrace.StopProfiler();
                Thread.Sleep(500);
            }
        }
Пример #8
0
 private static void MapInput(Input inputData, _InputMeta inputMeta)
 {
     PerformanceTimer.Reset();
     PerformanceTimer.Start();
     MapVoltagePhasorInput(inputData, inputMeta);
     MapCurrentPhasorInput(inputData, inputMeta);
     MapStatusWordInput(inputData, inputMeta);
     MapDigitalsInput(inputData, inputMeta);
     PerformanceTimer.Stop();
     m_network.PerformanceMetrics.ParsingExecutionTime = PerformanceTimer.ElapsedTicks;
 }
Пример #9
0
        private void LoadXmlFile()
        {
            PerformanceTimer timer = new PerformanceTimer();

            timer.Start();
            this._xmlDoc.Load(this._XmlFileName);
            timer.Stop();
            this.statusBar.Text          = "Xml Document Load Time: " + timer.ElapsedTime.ToString() + " ms";
            this.btnExecuteQuery.Enabled = true;
            this.FillXmlDocument(this._xmlDoc);
        }
Пример #10
0
        private void LoadXmlFile()
        {
            var timer = new PerformanceTimer();

            timer.Start();
            _xmlDoc.Load(_XmlFileName);
            timer.Stop();
            statusBar.Text          = "Xml Document Load Time: " + timer.ElapsedTime + " ms";
            btnExecuteQuery.Enabled = true;
            FillXmlDocument(_xmlDoc);
        }
Пример #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            //ThreadStart childref = new ThreadStart(bc);
            //Thread childThread = new Thread(childref);
            if (iff)
            {
                t   = 0;
                iff = false;
                timer.Start();
                //ThreadStart childref = new ThreadStart(bc);
                //Thread childThread = new Thread(childref);
                //childThread.Start();
            }
            else
            {
                //childThread.Abort();
                timer.Stop();
                t             = timer.Duration;
                textBox1.Text = t.ToString();
                textBox2.Text = (1 / t).ToString();
                textBox4.Text = Math.Round(1 / t, 3).ToString();
                if (cps < (1 / t))
                {
                    cps = 1 / t;
                }
                textBox3.Text = cps.ToString();
                if (Math.Round(1 / t, 3) - 4.317 < 0)
                {
                    textBox5.Text = "慢" + (4.317 - Math.Round(1 / t, 3)).ToString();
                }
                else
                {
                    textBox5.Text = "快" + (Math.Round(1 / t, 3) - 4.317).ToString();
                }

                timer.Start();
            }
        }
Пример #12
0
        private void btnExecuteQuery_Click(object sender, EventArgs e)
        {
            btnSelXPath.Enabled = false;
            _treeResult.BeginUpdate();
            _treeResult.Nodes.Clear();
            XmlNode documentElement = _xmlDoc.DocumentElement;
            var     node            = new TreeNode(_xmlString);

            _treeResult.Nodes.Add(node);
            try
            {
                var timer = new PerformanceTimer();
                timer.Start();
                XmlNodeList list = null;
                if (_hasNS)
                {
                    list = documentElement.SelectNodes(txtQuery.Text, _nsMgr);
                }
                else
                {
                    list = documentElement.SelectNodes(txtQuery.Text);
                }
                timer.Stop();
                statusBar.Text = "XPath Query -- Elapsed time: " + timer.ElapsedTime + " ms";
                for (var i = 0; i < list.Count; i++)
                {
                    Xml2Tree(node, list[i]);
                }
                isContextNode = true;
            }
            catch (XPathException exception)
            {
                MessageBox.Show("Error in XPath Query:" + exception.Message);
                btnSelXPath.Enabled = true;
                isContextNode       = false;
                return;
            }
            catch (XsltException exception2)
            {
                MessageBox.Show(exception2.Message);
                btnSelXPath.Enabled = true;
                isContextNode       = false;
                return;
            }
            _treeResult.EndUpdate();
            node.Expand();
        }
Пример #13
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 13 - Puzzle A ---");

            PerformanceTimer.Start();

            int result = PuzzleA.FirewallTraveler.CheckSeverityForPacket(@"Input\puzzlea.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #14
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 18 - Puzzle A ---");

            PerformanceTimer.Start();

            long result = PuzzleA.SoundProcessor.GetFirstRecoveredFrequency(@"Input\puzzlea.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #15
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 19 - Puzzle A ---");

            PerformanceTimer.Start();

            string result = PuzzleA.PathFollower.FollowPath(@"Input\puzzlea.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #16
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 19 - Puzzle B ---");

            PerformanceTimer.Start();

            int result = PuzzleB.PathFollower.CountSteps(@"Input\puzzleb.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #17
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 8 - Puzzle B ---");
            Console.WriteLine();

            PerformanceTimer.Start();

            int result = PuzzleB.RegisterManager.FindLargestValueEver(@"Input\puzzleb.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #18
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 23 - Puzzle A ---");

            PerformanceTimer.Start();

            long result = PuzzleA.InstructionProcessor.GetTimesMulWasUsed(@"Input\puzzlea.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #19
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 5 - Puzzle A ---");

            PerformanceTimer.Start();

            int result = PuzzleA.JumpCalculator.CalculateJumpsToEscape(@"Input\puzzlea.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #20
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 7 - Puzzle B ---");
            Console.WriteLine();

            PerformanceTimer.Start();

            int result = PuzzleB.TowerBuilder.FindBalancingWeight(@"Input\puzzleb.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #21
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 7 - Puzzle A ---");
            Console.WriteLine();

            PerformanceTimer.Start();

            string result = PuzzleA.TowerBuilder.FindBottomProgram(@"Input\puzzlea.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #22
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 23 - Puzzle B ---");

            PerformanceTimer.Start();

            int result = PuzzleB.InstructionProcessor.FindCompositesBetweenTwoNumbers(106700, 123700);

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #23
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 24 - Puzzle B ---");

            PerformanceTimer.Start();

            int result = PuzzleB.BridgeBuilder.DetermineStrengthOfLongestBridge(@"Input\puzzleb.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #24
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 4 - Puzzle A ---");

            PerformanceTimer.Start();

            int result = PuzzleA.FileParser.CountValidPassphrases(@"Input\puzzlea.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #25
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 18 - Puzzle B ---");

            PerformanceTimer.Start();

            long result = PuzzleB.InstructionProcessor.GetNumberOfValuesSent(@"Input\puzzleb.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #26
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 20 - Puzzle B ---");
            Console.WriteLine();

            PerformanceTimer.Start();

            int result = PuzzleB.ParticleSimulator.FindNumberOfNonCollisions(@"Input\puzzleb.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #27
0
        private static void RunPuzzleA()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 20 - Puzzle A ---");
            Console.WriteLine();

            PerformanceTimer.Start();

            int result = PuzzleA.ParticleSimulator.FindClosestParticle(@"Input\puzzlea.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine($"Puzzle A result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #28
0
        //private static void MapSwitchStatusOutput(Output output)
        //{
        //    Dictionary<string, OutputMeasurement> switchStatuses = m_network.Model.SwitchStatusOutput.ToDictionary(x => x.Key, x => x);

        //    for (int i = 0; i < output.OutputMeta.CircuitBreakerStatuses.Length; i++)
        //    {
        //        string key = output.OutputMeta.CircuitBreakerStatuses[i].ID.ToString();
        //        OutputMeasurement status = null;
        //        switchStatuses.TryGetValue(key, out status);
        //        if (status != null)
        //        {
        //            output.OutputData.CircuitBreakerStatuses[i] = status.Value;
        //        }
        //    }
        //}

        private static void MapTopologyProfilingOutput(Output output)
        {
            Dictionary <string, OutputMeasurement> topologyProfiling = m_network.Model.TopologyProfilingOutput.ToDictionary(x => x.Key, x => x);

            PerformanceTimer.Reset();
            PerformanceTimer.Start();
            for (int i = 0; i < output.OutputMeta.TopologyProfilingData.Length; i++)
            {
                string            key  = output.OutputMeta.TopologyProfilingData[i].ID.ToString();
                OutputMeasurement data = null;
                topologyProfiling.TryGetValue(key, out data);
                if (data != null)
                {
                    output.OutputData.TopologyProfilingData[i] = data.Value;
                }
            }
            PerformanceTimer.Stop();
            m_network.PerformanceMetrics.OutputPreparationExecutionTime += PerformanceTimer.ElapsedTicks;
        }
Пример #29
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 13 - Puzzle B ---");
            Console.WriteLine();

            PerformanceTimer.Start();

            int result = PuzzleB.FirewallTraveler.FindShortestDelay(@"Input\puzzleb.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }
Пример #30
0
        private static void RunPuzzleB()
        {
            // Intro message.
            Console.WriteLine("--- Begin Day 2 - Puzzle B ---");
            Console.WriteLine();

            PerformanceTimer.Start();

            int result = PuzzleB.FileParser.ComputeFileChecksum(@"Input\puzzleb.txt");

            PerformanceTimer.Stop();

            // Display results.
            Console.WriteLine();
            Console.WriteLine($"Puzzle B result: {result}");
            PerformanceTimer.LogTime();

            Console.WriteLine();
        }