public void RunTest() { int iterations = 5; // Call the object and methods to JIT before the test run QueryPerfCounter myTimer = new QueryPerfCounter(); myTimer.Start(); myTimer.Stop(); // Time the overall test duration DateTime dtStartTime = DateTime.Now; // Use QueryPerfCounters to get the average time per iteration myTimer.Start(); for (int i = 0; i < iterations; i++) { // Method to time System.Threading.Thread.Sleep(1000); } myTimer.Stop(); // Calculate time per iteration in nanoseconds double result = myTimer.Duration(iterations); // Show the average time per iteration results Data.Output.WriteLine("Iterations: {0}", iterations); Data.Output.WriteLine("Average time per iteration: "); Data.Output.WriteLine(result / 1000000000 + " seconds"); Data.Output.WriteLine(result / 1000000 + " milliseconds"); Data.Output.WriteLine(result + " nanoseconds"); // Show the overall test duration results DateTime dtEndTime = DateTime.Now; Double duration = ((TimeSpan)(dtEndTime - dtStartTime)).TotalMilliseconds; Data.Output.WriteLine(); Data.Output.WriteLine("Duration of test run: "); Data.Output.WriteLine(duration / 1000 + " seconds"); Data.Output.WriteLine(duration + " milliseconds"); }
public static string RunTest(string hostsFile, string pacName, bool ifMissing = false) { using (StreamReader hostsReader = new StreamReader(hostsFile)) { string pacUri = "http://localhost:8080/" + pacName + "?" + new Random().Next(); Console.WriteLine(pacUri); GC.Collect(); long memBefore = GC.GetTotalMemory(true); var myTimer = new QueryPerfCounter(); myTimer.Start(); int iterations = 0; string host; while ((host = hostsReader.ReadLine()) != null) { string uri = Proxy.GetProxyForUrlUsingPac("http://" + host, pacUri); if (ifMissing && uri != null || !ifMissing && uri == null) { Console.WriteLine("DIRECT !" + host + "!"); } //else Console.WriteLine("PROXY !" + uri + "!"); // For DEBUG. ++iterations; } myTimer.Stop(); // Calculate time per iteration in nanoseconds double duration = myTimer.Duration(iterations); long memAfter = GC.GetTotalMemory(false); long memUsage = memAfter - memBefore; double memPerAddr = memUsage / (double)iterations; var resultNs = Convert.ToInt32(duration).ToString(); var resultBytes = Convert.ToInt32(memPerAddr).ToString(); return(string.Format("{0} bytes, {1} ns", resultBytes, resultNs)); } }
static void Main(string[] args) { if (args.Length < 1) { return; } var cmd = string.Join(" ", args); var procStartInfo = new System.Diagnostics.ProcessStartInfo(); procStartInfo.FileName = "cmd.exe"; procStartInfo.Arguments = "/C " + cmd; procStartInfo.UseShellExecute = false; procStartInfo.RedirectStandardError = true; procStartInfo.RedirectStandardInput = true; procStartInfo.RedirectStandardOutput = true; var process = new System.Diagnostics.Process(); process.StartInfo = procStartInfo; process.OutputDataReceived += (sender, dataReceivedArgs) => Console.WriteLine(dataReceivedArgs.Data); process.ErrorDataReceived += (sender, dataReceivedArgs) => Console.WriteLine(dataReceivedArgs.Data); QueryPerfCounter timer = new QueryPerfCounter(); timer.Start(); { process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); process.CancelOutputRead(); } timer.Stop(); Console.WriteLine("Time elapsed: {0} ms", timer.Duration().ToString("F")); }
public static string RunTest(string hostsFile, string pacName, bool ifMissing = false) { using(StreamReader hostsReader = new StreamReader(hostsFile)) { string pacUri = "http://localhost:8080/"+pacName+"?"+new Random().Next(); Console.WriteLine(pacUri); GC.Collect(); long memBefore = GC.GetTotalMemory(true); var myTimer = new QueryPerfCounter(); myTimer.Start(); int iterations = 0; string host; while( (host = hostsReader.ReadLine()) != null ) { string uri = Proxy.GetProxyForUrlUsingPac( "http://"+host, pacUri ); if (ifMissing && uri != null || !ifMissing && uri == null) Console.WriteLine("DIRECT !" + host + "!"); //else Console.WriteLine("PROXY !" + uri + "!"); // For DEBUG. ++iterations; } myTimer.Stop(); // Calculate time per iteration in nanoseconds double duration = myTimer.Duration(iterations); long memAfter = GC.GetTotalMemory(false); long memUsage = memAfter - memBefore; double memPerAddr = memUsage / (double) iterations; var resultNs = Convert.ToInt32(duration).ToString(); var resultBytes = Convert.ToInt32(memPerAddr).ToString(); return string.Format( "{0} bytes, {1} ns", resultBytes, resultNs ); } }
public string max() { int max = 0; lock (thisLock) { Q.Start(); for (int i = 0; i < singleGrades.Length; i++) { if (singleGrades[i] > max) { max = singleGrades[i]; } } Q.Stop(); } duration = Q.Duration(1); return("max: " + max); }
private static void Update() { m_UIUpdateTimer.Stop(); double interframeDuration = m_UIUpdateTimer.Duration(); QueryPerfCounter uiIntraFrameTimer = new QueryPerfCounter(); uiIntraFrameTimer.Start(); // the frame queue is a shared resource with the FrameOfMocap delivery thread, so lock it while reading // note this can block the frame delivery thread. In a production application frame queue management would be optimized. lock (syncLock) { while (m_FrameQueue.Count > 0) { m_FrameOfData = m_FrameQueue.Dequeue(); if (m_FrameQueue.Count > 0) continue; if (m_FrameOfData != null) { // for servers that only use timestamps, not frame numbers, calculate a // frame number from the time delta between frames if (desc.HostApp.Contains("TrackingTools")) { m_fCurrentMocapFrameTimestamp = m_FrameOfData.fLatency; if (m_fCurrentMocapFrameTimestamp == m_fLastFrameTimestamp) { continue; } if (m_fFirstMocapFrameTimestamp == 0.0f) { m_fFirstMocapFrameTimestamp = m_fCurrentMocapFrameTimestamp; } m_FrameOfData.iFrame = (int)((m_fCurrentMocapFrameTimestamp - m_fFirstMocapFrameTimestamp) * m_ServerFramerate); } // update the mocap data UpdateData(); } } uiIntraFrameTimer.Stop(); double uiIntraFrameDuration = uiIntraFrameTimer.Duration(); m_UIUpdateTimer.Start(); } }
/// <summary> /// [NatNet] m_NatNet_OnFrameReady will be called when a frame of Mocap /// data has is received from the server application. /// /// Note: This callback is on the network service thread, so it is /// important to return from this function quickly as possible /// to prevent incoming frames of data from buffering up on the /// network socket. /// /// Note: "data" is a reference structure to the current frame of data. /// NatNet re-uses this same instance for each incoming frame, so it should /// not be kept (the values contained in "data" will become replaced after /// this callback function has exited). /// </summary> /// <param name="data">The actual frame of mocap data</param> /// <param name="client">The NatNet client instance</param> static void m_NatNet_OnFrameReady(NatNetML.FrameOfMocapData data, NatNetML.NatNetClientML client) { double elapsedIntraMS = 0.0f; QueryPerfCounter intraTimer = new QueryPerfCounter(); intraTimer.Start(); // detect and report and 'measured' frame drop (as measured by client) m_FramePeriodTimer.Stop(); double elapsedMS = m_FramePeriodTimer.Duration(); ProcessFrameOfData(ref data); // report if we are taking too long, which blocks packet receiving, which if long enough would result in socket buffer drop intraTimer.Stop(); elapsedIntraMS = intraTimer.Duration(); if (elapsedIntraMS > 5.0f) { Console.WriteLine("Warning : Frame handler taking too long: " + elapsedIntraMS.ToString("F2")); } m_FramePeriodTimer.Start(); }
private void toolStripButtonExcute_Click(object sender, EventArgs e) { try { toolStripStatusLabelReport.Text = ""; tabControl1.SelectedTab = tabPageResults; textBoxMessages.Text = ""; QueryPerfCounter qp = new QueryPerfCounter(); qp.Start(); int count = 0; SFQLParse sfqlParse = new SFQLParse(); string sql = textBoxSql.Text; if (!string.IsNullOrEmpty(textBoxSql.SelectedText)) { sql = textBoxSql.SelectedText; } if (sql.StartsWith("SP_", StringComparison.CurrentCultureIgnoreCase)) { sql = "exec " + sql; } if (performanceReportToolStripMenuItem.Checked) { sql = "[PerformanceReport]\r\n" + sql; } QueryResult queryResult; GlobalSetting.DataAccess.ResetDataCacheAfterTimeout = resetDataCacheAfterTimeoutToolStripMenuItem.Checked; if (dataCacheToolStripMenuItem.Checked) { queryResult = GlobalSetting.DataAccess.Excute(sql, 0); } else { queryResult = GlobalSetting.DataAccess.Excute(sql); } Hubble.Framework.Data.DataTable table = null; if (queryResult.DataSet.Tables.Count > 0) { table = queryResult.DataSet.Tables[0]; count = table.MinimumCapacity; } qp.Stop(); double ns = qp.Duration(1); StringBuilder report = new StringBuilder(); report.AppendFormat("Duration:{0} ", (ns / (1000 * 1000)).ToString("0.00") + " ms"); report.AppendFormat("Count={0}", count); if (queryResult.PrintMessages != null) { if (queryResult.PrintMessageCount > 0) { ShowMessages(queryResult.PrintMessages, table == null); } } MultiGridView mulitGridView = new MultiGridView(panelResult, queryResult.DataSet.Tables.Count); for (int i = 0; i < queryResult.DataSet.Tables.Count; i++) { queryResult.DataSet.Tables[i].MinimumCapacity = 0; mulitGridView.GridViewList[i].DataSource = queryResult.DataSet.Tables[i].ConvertToSystemDataTable(); DataTable tbl = queryResult.DataSet.Tables[i]; for (int j = 0; j < tbl.Columns.Count; j++) { if (tbl.Columns[j].DataType == typeof(DateTime)) { mulitGridView.GridViewList[i].Columns[j].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:sss"; } } } toolStripStatusLabelReport.Text = report.ToString(); if (performanceReportToolStripMenuItem.Checked) { tabControl1.SelectedTab = tabPageMessages; } } catch (Hubble.Core.SFQL.LexicalAnalysis.LexicalException lexicalEx) { ShowErrorMessage(lexicalEx.ToString()); } catch (Hubble.Core.SFQL.SyntaxAnalysis.SyntaxException syntaxEx) { ShowErrorMessage(syntaxEx.ToString()); } catch (Hubble.Framework.Net.ServerException e1) { ShowErrorMessage(e1.Message + "\r\n" + e1.StackTrace); } catch (Exception e1) { ShowErrorMessage(e1.Message + "\r\n" + e1.StackTrace); } finally { } textBoxSql.Focus(); }
private void buttonTest_Click(object sender, EventArgs e) { try { QueryPerfCounter qp = new QueryPerfCounter(); bool dataCacheEnabled = checkBoxDataCache.Checked; int dataCacheTimeout = -1; if (dataCacheEnabled) { dataCacheTimeout = (int)numericUpDownDataCache.Value; } qp.Start(); SFQLParse sfqlParse = new SFQLParse(); string sql = textBoxSql.Text; if (!string.IsNullOrEmpty(textBoxSql.SelectedText)) { sql = textBoxSql.SelectedText; } for (int i = 0; i < numericUpDownIteration.Value; i++) { if (dataCacheEnabled) { DataAccess.Excute(sql, dataCacheTimeout); } else { DataAccess.Excute(sql); } } qp.Stop(); double ns = qp.Duration(1); StringBuilder report = new StringBuilder(); report.AppendFormat("{0} ", (ns / ((long)1000 * (long)1000 * (int)numericUpDownIteration.Value)).ToString("0.00") + " ms"); labelDuration.Text = report.ToString(); } catch (Hubble.Core.SFQL.LexicalAnalysis.LexicalException lexicalEx) { ShowErrorMessage(lexicalEx.ToString()); } catch (Hubble.Core.SFQL.SyntaxAnalysis.SyntaxException syntaxEx) { ShowErrorMessage(syntaxEx.ToString()); } catch (Exception e1) { ShowErrorMessage(e1.Message + "\r\n" + e1.StackTrace); } finally { } }
private void button1_Click(object sender, EventArgs e) { try { QueryPerfCounter qp = new QueryPerfCounter(); SFQLParse sfqlParse = new SFQLParse(); string sql = textBoxSql.Text; if (!string.IsNullOrEmpty(textBoxSql.SelectedText)) { sql = textBoxSql.SelectedText; } Hubble.SQLClient.QueryResult result = DataAccess.Excute(sql); qp.Start(); for (int i = 0; i < numericUpDownIteration.Value; i++) { //MemoryStream s = Serialize(result, true); //Hubble.SQLClient.QueryResult r = // Hubble.SQLClient.QueryResultSerialization.Deserialize(s, true); //if (result.DataSet.Tables.Count == r.DataSet.Tables.Count) //{ // MessageBox.Show("OK"); //} //len = s.Length; //MemoryStream s = Hubble.Framework.Serialization.XmlSerialization<Hubble.SQLClient.QueryResult>.Serialize(result, Encoding.UTF8); //MemoryStream s = new MemoryStream(); //IFormatter formatter = new BinaryFormatter(); //formatter.Serialize(s, result); //s.Position = 0; //len = s.Length; //MemoryStream cs = Compress(s); //cs.Position = 0; //cs = DeCompress(cs); //cs.Position = 0; //formatter = new BinaryFormatter(); //formatter.Deserialize(s); //Hubble.Framework.Serialization.XmlSerialization<Hubble.SQLClient.QueryResult>.Deserialize(cs); } qp.Stop(); double ns = qp.Duration(1); StringBuilder report = new StringBuilder(); report.AppendFormat("{0} ", (ns / (1000 * 1000 * (int)numericUpDownIteration.Value)).ToString("0.00") + " ms"); labelDuration.Text = report.ToString(); } catch (Hubble.Core.SFQL.LexicalAnalysis.LexicalException lexicalEx) { ShowErrorMessage(lexicalEx.ToString()); } catch (Hubble.Core.SFQL.SyntaxAnalysis.SyntaxException syntaxEx) { ShowErrorMessage(syntaxEx.ToString()); } catch (Exception e1) { ShowErrorMessage(e1.Message + "\r\n" + e1.StackTrace); } finally { } }