本文整理汇总了C#中Stopwatch.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Stopwatch.Stop方法的具体用法?C# Stopwatch.Stop怎么用?C# Stopwatch.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsymmetricObjects
private void AsymmetricObjects()
{
Console.WriteLine("Asymmetric");
Console.WriteLine("----------");
// bind
var numberBinding = new Binding("Number") {Source = _guineaPig};
var nameBinding = new Binding("FullName") {Source = _guineaPig};
_subjectUnderTest.Number.SetBinding(System.Windows.Controls.TextBox.TextProperty, numberBinding);
_subjectUnderTest.FullName.SetBinding(System.Windows.Controls.TextBox.TextProperty, nameBinding);
var testDuration = new Stopwatch();
testDuration.Start();
RunAsymmetric();
testDuration.Stop();
Console.WriteLine(
string.Format("Write to {0}: {1} msec.", _subjectUnderTest.GetType().Name, testDuration.ElapsedMilliseconds.ToString("#,###")));
testDuration.Restart();
RunReverseAsymmetric();
testDuration.Stop();
Console.WriteLine(
string.Format("Write to {0}: {1} msec.", _guineaPig.GetType().Name, testDuration.ElapsedMilliseconds.ToString("#,###")));
Console.WriteLine();
}
示例2: run
public static void run(Action testMethod, int rounds){
Stopwatch stopwatch = new Stopwatch();
stopwatch.Reset();
stopwatch.Start();
while (stopwatch.ElapsedMilliseconds < 1200) // A Warmup of 1000-1500 mS
// stabilizes the CPU cache and pipeline.
{
testMethod(); // Warmup
clearMemory ();
}
stopwatch.Stop();
long totalmem;
Console.WriteLine ("Round;Runtime ms;Memory KB");
for (int repeat = 0; repeat < rounds; ++repeat)
{
stopwatch.Reset();
stopwatch.Start();
testMethod();
stopwatch.Stop();
totalmem = getUsedMemoryKB ();
clearMemory ();
Console.WriteLine((1+repeat)+";"+stopwatch.ElapsedMilliseconds + ";"
+totalmem);
}
}
示例3: Main
public static void Main()
{
Stopwatch watch = new Stopwatch();
Random rand = new Random();
watch.Start();
for (int i = 0; i < iterations; i++)
DayOfYear1(rand.Next(1, 13), rand.Next(1, 29));
watch.Stop();
Console.WriteLine("Local array: " + watch.Elapsed);
watch.Reset();
watch.Start();
for (int i = 0; i < iterations; i++)
DayOfYear2(rand.Next(1, 13), rand.Next(1, 29));
watch.Stop();
Console.WriteLine("Static array: " + watch.Elapsed);
// trying to modify static int []
daysCumulativeDays[0] = 18;
foreach (int days in daysCumulativeDays)
{
Console.Write("{0}, ", days);
}
Console.WriteLine("");
// MY_STR_CONST = "NOT CONST";
}
示例4: should_be_within_performace_tolerance
public void should_be_within_performace_tolerance()
{
var xml = File.ReadAllText("model.json").ParseJson();
var json = JElement.Load(File.ReadAllBytes("model.json"));
var stopwatch = new Stopwatch();
var controlBenchmark = Enumerable.Range(1, 1000).Select(x =>
{
stopwatch.Restart();
xml.EncodeJson();
stopwatch.Stop();
return stopwatch.ElapsedTicks;
}).Skip(5).Average();
var flexoBenchmark = Enumerable.Range(1, 1000).Select(x =>
{
stopwatch.Restart();
json.Encode();
stopwatch.Stop();
return stopwatch.ElapsedTicks;
}).Skip(5).Average();
Console.Write("Control: {0}, Flexo: {1}", controlBenchmark, flexoBenchmark);
flexoBenchmark.ShouldBeLessThan(controlBenchmark * 5);
}
示例5: ECPerformanceTest
public void ECPerformanceTest()
{
Stopwatch sw = new Stopwatch();
int timesofTest = 1000;
string[] timeElapsed = new string[2];
string testCase = "sdg;alwsetuo1204985lkscvzlkjt;";
sw.Start();
for(int i = 0; i < timesofTest; i++)
{
this.Encode(testCase, 3);
}
sw.Stop();
timeElapsed[0] = sw.ElapsedMilliseconds.ToString();
sw.Reset();
sw.Start();
for(int i = 0; i < timesofTest; i++)
{
this.ZXEncode(testCase, 3);
}
sw.Stop();
timeElapsed[1] = sw.ElapsedMilliseconds.ToString();
Assert.Pass("EC performance {0} Tests~ QrCode.Net: {1} ZXing: {2}", timesofTest, timeElapsed[0], timeElapsed[1]);
}
示例6: btnInterpretate_Click
private void btnInterpretate_Click(object sender, EventArgs e)
{
try
{
Stopwatch timer = new Stopwatch();
RegularExpression r;
timer.Reset();
timer.Start();
r = new RegularExpression(txtRegEx.Text);
timer.Stop();
ReportResult("Parsing '" + txtRegEx.Text + "'", "SUCCESS", r.IsCompiled, timer);
timer.Reset();
timer.Start();
bool result = r.IsMatch(txtInput.Text);
timer.Stop();
ReportResult("Matching '" + txtInput.Text + "'", result.ToString(), r.IsCompiled, timer);
ReportData("Original Expression:\t" + r.OriginalExpression + "\r\nInfix Expression:\t" + r.FormattedExpression + "\r\nPostfix string:\t" + r.PostfixExpression + "\r\n\r\nNon Deterministic Automata has\t\t" + r.NDStateCount + " states.\r\nDeterministic Automata has\t\t" + r.DStateCount + " states.\r\nOptimized Deterministic Automata has\t" + r.OptimizedDStateCount + " states.");
automataViewer1.Initialize(r);
}
catch (RegularExpressionParser.RegularExpressionParserException exc)
{
ReportError("PARSER ERROR", exc.ToString());
}
catch (Exception exc)
{
ReportError("EXCEPTION", exc.ToString());
}
}
示例7: BackSequentialCompare
public static void BackSequentialCompare(int countOfElementInArray)
{
int[] intArray = new int[countOfElementInArray];
double[] doubleArray = new double[countOfElementInArray];
string[] stringArray = new string[countOfElementInArray];
for (int i = countOfElementInArray - 1; i >= 0; i--)
{
intArray[i] = i;
doubleArray[i] = i;
stringArray[i] = i.ToString();
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Restart();
QuickSort<int>.Sort(intArray, Comparer<int>.Default);
stopwatch.Stop();
Console.WriteLine("Quick sort result for back sequential int is:{0}", stopwatch.ElapsedMilliseconds);
stopwatch.Restart();
QuickSort<double>.Sort(doubleArray, Comparer<double>.Default);
stopwatch.Stop();
Console.WriteLine("Quick sort result for back sequential double is:{0}", stopwatch.ElapsedMilliseconds);
stopwatch.Restart();
QuickSort<string>.Sort(stringArray, Comparer<string>.Default);
stopwatch.Stop();
Console.WriteLine("Quick sort result for back sequential string is:{0}", stopwatch.ElapsedMilliseconds);
}
示例8: RunWithContext
private static void RunWithContext(string topic, int iterations, Federation federation)
{
using (RequestContext.Create())
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
string content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null);
stopwatch.Stop();
Console.WriteLine("Rendered first times in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F);
stopwatch.Reset();
stopwatch.Start();
content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null);
stopwatch.Stop();
Console.WriteLine("Rendered second time in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F);
stopwatch.Reset();
stopwatch.Start();
content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null);
stopwatch.Stop();
Console.WriteLine("Rendered third time in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F);
}
}
示例9: TestCutLargeFile
public void TestCutLargeFile()
{
var weiCheng = File.ReadAllText(@"Resources\围城.txt");
var seg = new JiebaSegmenter();
seg.Cut("热身");
Console.WriteLine("Start to cut");
var n = 20;
var stopWatch = new Stopwatch();
// Accurate mode
stopWatch.Start();
for (var i = 0; i < n; i++)
{
seg.Cut(weiCheng);
}
stopWatch.Stop();
Console.WriteLine("Accurate mode: {0} ms", stopWatch.ElapsedMilliseconds / n);
// Full mode
stopWatch.Reset();
stopWatch.Start();
for (var i = 0; i < n; i++)
{
seg.Cut(weiCheng, true);
}
stopWatch.Stop();
Console.WriteLine("Full mode: {0} ms", stopWatch.ElapsedMilliseconds / n);
}
示例10: Test_perf_of_query_without_index
public void Test_perf_of_query_without_index()
{
OdbFactory.Delete("index1perf.ndb");
using (var odb = OdbFactory.Open("index1perf.ndb"))
{
for (var i = 0; i < 5000; i++)
{
var player = new Player("Player" + i, DateTime.Now, new Sport("Sport" + i));
odb.Store(player);
}
}
var stopwatch = new Stopwatch();
stopwatch.Start();
using (var odb = OdbFactory.OpenLast())
{
var query = odb.Query<Player>();
query.Descend("Name").Constrain((object) "Player20").Equal();
var count = query.Execute<Player>().Count;
Assert.That(count, Is.EqualTo(1));
}
stopwatch.Stop();
Console.WriteLine("Elapsed {0} ms", stopwatch.ElapsedMilliseconds);
stopwatch.Reset();
stopwatch.Start();
using (var odb = OdbFactory.OpenLast())
{
var query = odb.Query<Player>();
query.Descend("Name").Constrain((object) "Player1234").Equal();
var count = query.Execute<Player>().Count;
Assert.That(count, Is.EqualTo(1));
}
stopwatch.Stop();
Console.WriteLine("Elapsed {0} ms", stopwatch.ElapsedMilliseconds);
stopwatch.Reset();
stopwatch.Start();
using (var odb = OdbFactory.OpenLast())
{
var query = odb.Query<Player>();
query.Descend("Name").Constrain((object) "Player4444").Equal();
var count = query.Execute<Player>().Count;
Assert.That(count, Is.EqualTo(1));
}
stopwatch.Stop();
Console.WriteLine("Elapsed {0} ms", stopwatch.ElapsedMilliseconds);
stopwatch.Reset();
stopwatch.Start();
using (var odb = OdbFactory.OpenLast())
{
var query = odb.Query<Player>();
query.Descend("Name").Constrain((object) "Player3211").Equal();
var count = query.Execute<Player>().Count;
Assert.That(count, Is.EqualTo(1));
}
stopwatch.Stop();
Console.WriteLine("Elapsed {0} ms", stopwatch.ElapsedMilliseconds);
}
示例11: FindAndSaveApps
private int FindAndSaveApps(ICollection<int> partition) {
ICollection<App> apps = appParser.RetrieveApps(partition);
if (apps == null) {
return 0;
}
Stopwatch watch = new Stopwatch();
watch.Start();
foreach (App app in apps) {
repository.App.Save(app);
indexer.AddApp(app);
}
watch.Stop();
logger.Debug("Saved {0} apps using {1}ms", apps.Count, watch.ElapsedMilliseconds);
watch.Reset();
watch.Start();
indexer.Flush();
watch.Stop();
logger.Debug("Indexed {0} apps using {1}ms", apps.Count, watch.ElapsedMilliseconds);
return apps.Count;
}
示例12: WillWaitForItem
public void WillWaitForItem() {
using (var queue = GetQueue()) {
queue.DeleteQueue();
TimeSpan timeToWait = TimeSpan.FromSeconds(1);
var sw = new Stopwatch();
sw.Start();
var workItem = queue.Dequeue(timeToWait);
sw.Stop();
Trace.WriteLine(sw.Elapsed);
Assert.Null(workItem);
Assert.True(sw.Elapsed > timeToWait.Subtract(TimeSpan.FromMilliseconds(10)));
Task.Factory.StartNewDelayed(100, () => queue.Enqueue(new SimpleWorkItem {
Data = "Hello"
}));
sw.Reset();
sw.Start();
workItem = queue.Dequeue(timeToWait);
workItem.Complete();
sw.Stop();
Trace.WriteLine(sw.Elapsed);
Assert.NotNull(workItem);
}
}
示例13: Start
// Use this for initialization
void Start()
{
if (SVGFile != null) {
Stopwatch w = new Stopwatch();
w.Reset();
w.Start();
ISVGDevice device;
if(useFastButBloatedRenderer)
device = new SVGDeviceFast();
else
device = new SVGDeviceSmall();
m_implement = new Implement(this.SVGFile, device);
w.Stop();
long c = w.ElapsedMilliseconds;
w.Reset();
w.Start();
m_implement.StartProcess();
w.Stop();
long p = w.ElapsedMilliseconds;
w.Reset();
w.Start();
renderer.material.mainTexture = m_implement.GetTexture();
w.Stop();
long r = w.ElapsedMilliseconds;
UnityEngine.Debug.Log("Construction: " + Format(c) + ", Processing: " + Format(p) + ", Rendering: " + Format(r));
Vector2 ts = renderer.material.mainTextureScale;
ts.x *= -1;
renderer.material.mainTextureScale = ts;
renderer.material.mainTexture.filterMode = FilterMode.Trilinear;
}
}
示例14: BinaryStressTest
public void BinaryStressTest()
{
var b = new Truck("MAN");
var upper = Math.Pow(10, 3);
var sw = new Stopwatch();
sw.Start();
b.LoadCargo(BinaryTestModels.ToList());
sw.Stop();
var secondElapsedToAdd = sw.ElapsedMilliseconds;
Trace.WriteLine(string.Format("Put on the Channel {1} items. Time Elapsed: {0}", secondElapsedToAdd, upper));
sw.Reset();
sw.Start();
b.DeliverTo("Dad");
sw.Stop();
var secondElapsedToBroadcast = sw.ElapsedMilliseconds ;
Trace.WriteLine(string.Format("Broadcast on the Channel {1} items. Time Elapsed: {0}", secondElapsedToBroadcast, upper));
var elem = b.UnStuffCargo<List<BinaryTestModel>>().First();
Assert.AreEqual(elem.Count(), 1000, "Not every elements have been broadcasted");
Assert.IsTrue(secondElapsedToAdd < 5000, "Add took more than 5 second. Review the logic, performance must be 10000 elems in less than 5 sec");
Assert.IsTrue(secondElapsedToBroadcast < 3000, "Broadcast took more than 3 second. Review the logic, performance must be 10000 elems in less than 5 sec");
}
示例15: CopyConstructorSpeed
public void CopyConstructorSpeed()
{
var random = new Random();
var values = new double[5000000];
for (var i = 0; i < 5000000; i++)
{
values[i] = random.Next();
}
var scalarSet = new ScalarSet(values);
// copying values
var stopwatch = new Stopwatch();
stopwatch.Start();
values.Clone();
stopwatch.Stop();
var copyArrayTime = stopwatch.ElapsedMilliseconds;
Trace.WriteLine("Copying array with 1M values took: " + copyArrayTime + " ms");
stopwatch.Reset();
stopwatch.Start();
new ScalarSet(scalarSet);
stopwatch.Stop();
Trace.WriteLine("Copying scalar set with 1M values took: " + stopwatch.ElapsedMilliseconds + " ms");
var fraction = stopwatch.ElapsedMilliseconds/copyArrayTime;
Assert.IsTrue(fraction < 1.1);
}