本文整理汇总了C#中System.Diagnostics.Stopwatch.Start方法的典型用法代码示例。如果您正苦于以下问题:C# System.Diagnostics.Stopwatch.Start方法的具体用法?C# System.Diagnostics.Stopwatch.Start怎么用?C# System.Diagnostics.Stopwatch.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Stopwatch
的用法示例。
在下文中一共展示了System.Diagnostics.Stopwatch.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
var ControllerIPAddress = new IPAddress(new byte[] { 192, 168, 0, 2 });
var ControllerPort = 40001;
var ControllerEndPoint = new IPEndPoint(ControllerIPAddress, ControllerPort);
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var header = "@";
var command = "00C";
var checksum = "E3";
var end = "\r\n";
var data = header + command + checksum + end;
byte[] bytes = new byte[1024];
//Start Connect
_connectDone.Reset();
watch.Start();
_client.BeginConnect(ControllerIPAddress, ControllerPort, new AsyncCallback(ConnectCallback), _client);
//wait 2s
_connectDone.WaitOne(2000, false);
var text = (_client.Connected) ? "ok" : "ng";
richTextBox1.AppendText(text + "\r\n");
watch.Stop();
richTextBox1.AppendText("Consumer time: " + watch.ElapsedMilliseconds + "\r\n");
}
示例2: btnVector_Click
/// <summary>
/// Tests for Vektor class
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnVector_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();
txtVector.Text = "Starting test suite for the Vektor class.\r\n\r\n";
// Sample data
List<Eksam.Vektor> vectors = new List<Vektor>{
new Vektor(),
new Vektor(1,1),
new Vektor(0,1),
new Vektor(2.2, 1.2),
new Vektor(10,-4),
null
};
// Go over all defined operations and input combinations
foreach (Vektor vector in vectors)
{
foreach (Vektor secondVector in vectors)
{
txtVector.Text += vector + " + " + secondVector + " = " + (vector + secondVector) + "\r\n";
txtVector.Text += vector + " - " + secondVector + " = " + (vector - secondVector) + "\r\n";
txtVector.Text += vector + " == " + secondVector + " ... " + (vector == secondVector) + "\r\n";
txtVector.Text += vector + vector + " (length " + (vector == null ? 0 : vector.Length()) + ") > " + secondVector + " (length " + (secondVector == null ? 0 : secondVector.Length()) + ")" + " ... " + (vector > secondVector) + "\r\n";
txtVector.Text += vector + vector + " (length " + (vector == null ? 0 : vector.Length()) + ") < " + secondVector + " (length " + (secondVector == null ? 0 : secondVector.Length()) + ")" + " ... " + (vector < secondVector) + "\r\n";
}
}
watch.Stop();
double elapsed = watch.ElapsedMilliseconds;
txtVector.Text += "\r\nTest suite finished, time elapsed: " + elapsed + "ms.";
}
示例3: MeasureStopwatch
public void MeasureStopwatch()
{
var sw = new System.Diagnostics.Stopwatch();
var measured = new System.Diagnostics.Stopwatch();
sw.Reset();
sw.Start();
measured.Start();
measured.Stop();
var warmupTemp = measured.ElapsedMilliseconds;
sw.Stop();
var warmupTime = sw.ElapsedMilliseconds;
measured.Reset();
sw.Reset();
sw.Start();
sw.Stop();
var originalTime = sw.ElapsedMilliseconds;
sw.Reset();
sw.Start();
for (var i = 0; i < 1000000; i++)
{
measured.Start();
measured.Stop();
var temp = measured.ElapsedMilliseconds;
}
sw.Stop();
var measuredTime = sw.ElapsedMilliseconds;
Console.WriteLine(measuredTime - originalTime);
}
示例4: Main
static void Main(string[] args)
{
string s = System.IO.File.ReadAllText(@"example.json");
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
for (int i = 0; i < 10000; i++)
Fairytale.JsonDeserializer.Deserialize(s);
sw.Stop();
Console.WriteLine(sw.Elapsed);
sw.Reset();
sw.Start();
for (int i = 0; i < 10000; i++)
Newtonsoft.Json.JsonConvert.DeserializeObject(s);
sw.Stop();
Console.WriteLine(sw.Elapsed);
sw.Reset();
sw.Start();
var parser = new System.Text.Json.JsonParser();
for (int i = 0; i < 10000; i++)
parser.Parse(s);
sw.Stop();
Console.WriteLine(sw.Elapsed);
Console.ReadLine();
}
示例5: button2_Click
private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
label3.Text = "???ms";
label4.Text = "Total is ";
richTextBox1.Text = "";
sw.Reset();
sw.Start();
List<int> resultList = primeNumbers.LinearSieve((int)numericUpDown1.Value, (int)numericUpDown2.Value);
sw.Stop();
label3.Text = (sw.Elapsed.TotalMilliseconds.ToString() + " ms").ToString();
label4.Text = "Total is " + resultList.Count;
sw.Start();
string a = string.Join(",", resultList.ToArray());
//sw.Stop();
//Console.WriteLine((sw.Elapsed.TotalMilliseconds.ToString() + " ms").ToString());
richTextBox1.Invoke((MethodInvoker)delegate {
//sw.Reset();
//sw.Start();
richTextBox1.AppendText(a);
sw.Stop();
label3.Text = label3.Text + "/" + (sw.Elapsed.TotalMilliseconds.ToString() + " ms").ToString();
}
);
}
示例6: TestExecuteIntersectionQuery
public void TestExecuteIntersectionQuery()
{
NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")),
"Specified shapefile is not present!");
var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), false, false);
shp.Open();
var fds = new SharpMap.Data.FeatureDataSet();
var bbox = shp.GetExtents();
//narrow it down
bbox.ExpandBy(-0.425*bbox.Width, -0.425*bbox.Height);
//Just to avoid that initial query does not impose performance penalty
shp.DoTrueIntersectionQuery = false;
shp.ExecuteIntersectionQuery(bbox, fds);
fds.Tables.RemoveAt(0);
//Perform query once more
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
shp.ExecuteIntersectionQuery(bbox, fds);
sw.Stop();
System.Console.WriteLine("Queried using just envelopes:\n" + fds.Tables[0].Rows.Count + " in " +
sw.ElapsedMilliseconds + "ms.");
fds.Tables.RemoveAt(0);
shp.DoTrueIntersectionQuery = true;
sw.Reset();
sw.Start();
shp.ExecuteIntersectionQuery(bbox, fds);
sw.Stop();
System.Console.WriteLine("Queried using prepared geometries:\n" + fds.Tables[0].Rows.Count + " in " +
sw.ElapsedMilliseconds + "ms.");
}
示例7: TestFromTxtFile
public void TestFromTxtFile(string file)
{
var wordUtil = new WordDict();
var expectWordCount = 0;
using (var sr = new StreamReader(file, Encoding.UTF8))
{
string line = null;
while ((line = sr.ReadLine()) != null)
{
if (line == string.Empty) continue;
wordUtil.Add(line);
expectWordCount++;
}
}
var watcher = new System.Diagnostics.Stopwatch();
watcher.Start();
var ms = new MemoryStream();
wordUtil.SaveTo(ms);
watcher.Stop();
Console.WriteLine("build dawg elapsed time:" + watcher.Elapsed.TotalMilliseconds + "'ms");
watcher.Reset();
watcher.Start();
ms.Position = 0;
wordUtil = WordDict.LoadFrom(ms);
watcher.Stop();
Console.WriteLine("load dawg file elapsed time:" + watcher.Elapsed.TotalMilliseconds + "'ms");
Assert.AreEqual(expectWordCount, wordUtil.Count);
}
示例8: Main
static void Main(string[] args)
{
TwitchPlays.ChannelName = "fluzzarn";
TwitchPlays.NickName = "Fluzzarn";
TwitchPlays.Password = Password.OAuthPWord;
TwitchPlays.ServerAddress = "irc.twitch.tv";
TwitchPlays.Connect();
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
kappa k = printKapps;
TwitchPlays.AddCommandToFunction("Kappa",printKapps);
TwitchPlays.AddCommandToFunction("exit", quit);
TwitchPlays.AddCommandToFunction("quit", quit);
while(true)
{
if(timer.ElapsedMilliseconds > 5000)
{
string command = TwitchPlays.GetMostCommonCommand();
int amount = TwitchPlays.GetFrequencyOfCommand(command);
Console.WriteLine("Most common input was: " + command + " with " + amount + " instances");
TwitchPlays.ExecuteCommand(command);
TwitchPlays.ClearCommands();
timer.Reset();
timer.Start();
}
}
}
示例9: Main
static void Main()
{
Scene scene = new Scene();
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();
GameTime time = new GameTime();
MessagePump.Run(scene.GraphicsEngine.Form, () =>
{
watch.Reset();
watch.Start();
int frameTime = 1;
if (time.LastFrameElapsedTime.TotalMilliseconds < frameTime)
System.Threading.Thread.Sleep((int)(frameTime - time.LastFrameElapsedTime.TotalMilliseconds));
scene.Update(time);
scene.Draw();
watch.Stop();
time.LastFrameElapsedTime = watch.Elapsed;
time.TotalGameTime = time.TotalGameTime + watch.Elapsed;
});
scene.Dispose();
// TODO ce soir
// frustrum culling pour la planète.
// backface culling pour le ground.
//
}
示例10: Main
public static void Main(string[] args)
{
Director.Initialize ();
Director.Instance.GL.Context.SetClearColor(255,255,255,0);
walker = new Walker("run.png", "run.xml");
var scene = new Scene();
scene.Camera.SetViewFromViewport();
SpriteTile sprite = walker.Get("walkLeft00");
sprite.Position = scene.Camera.CalcBounds().Center;
sprite.CenterSprite();
sprite.Scale = new Vector2(1,1);
scene.AddChild(sprite);
Director.Instance.RunWithScene(scene, true);
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
int spriteOffset = 0;
timer.Start();
bool walkLeft = true;
while(true) {
if(timer.ElapsedMilliseconds > 25f) {
string spriteName;
if(walkLeft) {
spriteName = "walkLeft";
sprite.Position = new Vector2(sprite.Position.X - 10, sprite.Position.Y);
} else {
spriteName = "walkRight";
sprite.Position = new Vector2(sprite.Position.X + 10, sprite.Position.Y);
}
if(sprite.Position.X < 0) {
walkLeft = false;
}
if(sprite.Position.X > Director.Instance.GL.Context.GetViewport().Width) {
walkLeft = true;
}
spriteName += spriteOffset.ToString("00");
sprite.TileIndex2D = walker.Get(spriteName).TileIndex2D;
if(spriteOffset >= 8) {
spriteOffset = 0;
} else {
spriteOffset ++;
}
timer.Reset();
timer.Start();
}
Director.Instance.Update();
Director.Instance.Render();
Director.Instance.GL.Context.SwapBuffers();
Director.Instance.PostSwap();
}
}
示例11: Time
private long Time(Action toDo, int repetitions)
{
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
{
stopwatch.Start();
for (int i = 0; i < repetitions; i ++)
{
toDo();
}
}
stopwatch.Stop();
return stopwatch.ElapsedTicks;
}
示例12: TestWarpedLineSymbolizer
public void TestWarpedLineSymbolizer()
{
var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);
var l = new SharpMap.Layers.VectorLayer("roads", p);
var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer();
cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 2) });
cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetGreaterSeries(3, 3), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1) });
l.Style.LineSymbolizer = cls;
var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) {BackColor = System.Drawing.Color.Cornsilk};
m.Layers.Add(l);
m.ZoomToExtents();
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
var bmp = m.GetMap();
sw.Stop();
System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("AurichRoads1.bmp");
cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
{
Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetTriangleSeries(4, 7),
Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
};
sw.Start();
bmp = m.GetMap();
sw.Stop();
System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("AurichRoads2.bmp");
//cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1];
cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
{
Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetZigZag(4, 4),
Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
//Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
};
sw.Start();
bmp = m.GetMap();
sw.Stop();
System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("AurichRoads3.bmp");
}
示例13: Block
static Block ()
{
#if !MF_FRAMEWORK_VERSION_V4_3
sw = new System.Diagnostics.Stopwatch ();
sw.Start ();
#endif
}
示例14: Performance
//[TestMethod]
public void Performance()
{
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
for (var i = 0; i < 200; i++) this.DefinedIPlugin();
Assert.IsTrue(sw.ElapsedMilliseconds < 2000);
}
示例15: InterOpSpeed
public void InterOpSpeed()
{
const int TESTSIZE = 100;
count = 0;
// get some random prices
Tick[] data = RandomTicks.GenerateSymbol(sym, TESTSIZE);
// track the time
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
int bad = 0;
sw.Start();
for (int i = 0; i < data.Length; i++)
{
int err = SendOrder(sym, true, 300, (double)data[i].trade, 0, 1, "TESTACCOUNT", "TESTDEST");
if (err!=0) bad++;
}
sw.Stop();
long elapms = sw.ElapsedMilliseconds;
double elap = (double)elapms/1000;
double rate = TESTSIZE / elap;
Console.WriteLine("InterOpSpeed elap: " + elap.ToString("N1") + " rate: " + rate.ToString("N0") + " orders/sec");
// make sure orders received
Assert.AreEqual(data.Length, count);
// make sure no bad orders
Assert.AreEqual(0,bad);
// make sure fast
Assert.LessOrEqual(elap, .5);
}