本文整理汇总了C#中System.Diagnostics.Stopwatch.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Stopwatch.Reset方法的具体用法?C# Stopwatch.Reset怎么用?C# Stopwatch.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.Reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestTryConvertPerformance
public void TestTryConvertPerformance()
{
double NUM_ITERATIONS = Math.Pow(10, 6);
Stopwatch watch = new Stopwatch();
Trace.WriteLine("Converting ints");
watch.Start();
for (double i = 0; i < NUM_ITERATIONS; i++)
{
int test = TypeUtils.TryConvert<int>("1234");
}
watch.Stop();
Trace.WriteLine("Elapsed Time: " + watch.Elapsed.TotalSeconds);
watch.Reset();
Trace.WriteLine("Converting int?s");
watch.Start();
for (double i = 0; i < NUM_ITERATIONS; i++)
{
int? test = TypeUtils.TryConvert<int?>("1234");
}
watch.Stop();
Trace.WriteLine("Elapsed Time: " + watch.Elapsed.TotalSeconds);
watch.Reset();
}
示例2: Main
static void Main(string[] args)
{
var sw = new Stopwatch();
Console.WriteLine("The difference between the sum of the squares of the first one hundred natural numbers and the square of the sum");
sw.Start();
var num1 = BruteForceWay(100);
sw.Stop();
Console.WriteLine(string.Format("Plain loop addition brute force way(Linq aggregate)(tick:{0}): {1}", sw.ElapsedTicks, num1));
sw.Reset();
Console.WriteLine("The difference between the sum of the squares of the first one hundred natural numbers and the square of the sum");
sw.Start();
var num3 = BruteForceWay2(100);
sw.Stop();
Console.WriteLine(string.Format("Plain loop addition brute force way(for loop)(tick:{0}): {1}", sw.ElapsedTicks, num3));
sw.Reset();
Console.WriteLine("The difference between the sum of the squares of the first one hundred natural numbers and the square of the sum");
sw.Start();
var num2 = ArithmeticWay(100);
sw.Stop();
Console.WriteLine(string.Format("Smart Arithmetic Way(tick:{0}): {1}", sw.ElapsedTicks, num2));
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
示例3: WillThrottleCalls
public void WillThrottleCalls()
{
var locker = GetLockProvider();
if (locker == null)
return;
// sleep until start of throttling period
Thread.Sleep(DateTime.Now.Ceiling(_period) - DateTime.Now);
var sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 5; i++)
locker.AcquireLock("test");
sw.Stop();
_output.WriteLine(sw.Elapsed.ToString());
Assert.True(sw.Elapsed.TotalSeconds < 1);
sw.Reset();
sw.Start();
var result = locker.AcquireLock("test", acquireTimeout: TimeSpan.FromMilliseconds(250));
sw.Stop();
Assert.Null(result);
_output.WriteLine(sw.Elapsed.ToString());
sw.Reset();
sw.Start();
result = locker.AcquireLock("test", acquireTimeout: TimeSpan.FromSeconds(4));
sw.Stop();
Assert.NotNull(result);
_output.WriteLine(sw.Elapsed.ToString());
}
示例4: Main
private static void Main(string[] args)
{
Stopwatch s1 = new Stopwatch();
s1.Start();
double serialPi = SerialEstimationOfPi();
s1.Stop();
System.Console.WriteLine("Serial: {0}", s1.ElapsedMilliseconds);
s1.Reset();
s1.Start();
double naiveParallelPi = NaiveParallelPi();
s1.Stop();
System.Console.WriteLine("Naive Parallel: {0}", s1.ElapsedMilliseconds);
s1.Reset();
s1.Start();
double parallelpi = ParallelPi();
s1.Stop();
System.Console.WriteLine("Parallel: {0}", s1.ElapsedMilliseconds);
s1.Reset();
s1.Start();
double parallelPartitionerPi = ParallelPartitionerPi();
s1.Stop();
System.Console.WriteLine("Parallel with partitioner: {0}", s1.ElapsedMilliseconds);
}
示例5: Main
static void Main() {
Stopwatch crono = new Stopwatch();
float tMono, tForEach, tFor;
crono.Start();
string[] ficheros = Directory.GetFiles(@"..\..\..\pics", "*.jpg");
string nuevoDirectorio = @"..\..\..\pics\rotadas";
Directory.CreateDirectory(nuevoDirectorio);
crono.Start();
VersionMonoHilo(ficheros, nuevoDirectorio);
crono.Stop();
tMono = crono.ElapsedMilliseconds;
Console.WriteLine("Ejecutado monohilo en {0:N} milisegundos.\n", tMono);
crono.Reset();
crono.Start();
VersionForEach(ficheros, nuevoDirectorio);
crono.Stop();
tForEach = crono.ElapsedMilliseconds;
Console.WriteLine("Ejecutado ForEach en {0:N} milisegundos.\n", tForEach);
crono.Reset();
crono.Start();
VersionFor(ficheros, nuevoDirectorio);
crono.Stop();
tFor = crono.ElapsedMilliseconds;
Console.WriteLine("Ejecutado For en {0:N} milisegundos.\n", tFor);
float beneficio = 100 - ((tForEach / tMono) * 100);
Console.WriteLine("Beneficio de rendimiento Mono vs ForEach {0:N} %", beneficio);
beneficio = 100 - ((tFor / tMono) * 100);
Console.WriteLine("Beneficio de rendimiento Mono vs For {0:N} %\n", beneficio);
}
示例6: DoubleOperations
private static void DoubleOperations()
{
Stopwatch sw = new Stopwatch();
sw.Start();
double result = 0;
for (int i = 0; i < count; i++)
{
result = Math.Sqrt(7);
}
Console.WriteLine("Math.Sqrt(): {0}", sw.Elapsed);
sw.Reset();
sw.Start();
for (int i = 0; i < count; i++)
{
result = Math.Log(7);
}
Console.WriteLine("Math.Log(): {0}", sw.Elapsed);
sw.Reset();
sw.Start();
for (int i = 0; i < count; i++)
{
result = Math.Sin(7);
}
Console.WriteLine("Math.Sin(): {0}", sw.Elapsed);
}
示例7: Main
static void Main(string[] args)
{
List<Tuple<string, int, long>> results = new List<Tuple<string, int, long>>();
Stopwatch stopWatch = new Stopwatch();
DataTable dataTable;
for (int testCount = 10; testCount <= 1000000; testCount *= 10)
{
GC.Collect();
dataTable = CreateTestTable(testCount);
stopWatch.Reset();
stopWatch.Start();
RunManualAssignmentTest(dataTable);
stopWatch.Stop();
results.Add(new Tuple<string, int, long>("Manual Assignment", testCount, stopWatch.ElapsedMilliseconds));
dataTable.Dispose();
GC.Collect();
dataTable = CreateTestTable(testCount);
stopWatch.Reset();
stopWatch.Start();
RunStaticAssignmentTest(dataTable);
stopWatch.Stop();
results.Add(new Tuple<string, int, long>("Static RuntimeMapper", testCount, stopWatch.ElapsedMilliseconds));
dataTable.Dispose();
GC.Collect();
dataTable = CreateTestTable(testCount);
stopWatch.Reset();
stopWatch.Start();
RunPreCachedAssignmentTest(dataTable);
stopWatch.Stop();
results.Add(new Tuple<string, int, long>("Cached RuntimeMapper", testCount, stopWatch.ElapsedMilliseconds));
dataTable.Dispose();
GC.Collect();
}
var csvFile = @"performanceTest_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv";
System.IO.File.AppendAllText(csvFile, "Test,Count,Time (ms)\n");
foreach (var result in results)
{
Console.WriteLine(result.Item1 + " (" + result.Item2 + "): " + result.Item3.ToString() + "ms");
Console.WriteLine("--------------------");
System.IO.File.AppendAllText(csvFile, result.Item1 + "," + result.Item2.ToString() + "," + result.Item3.ToString() + "\n");
}
Console.ReadKey();
}
示例8: Main
private static void Main()
{
// Testing different type of reverse algorithms
Stopwatch timeTest = new Stopwatch();
Console.Write("Enter some string: ");
string str = Console.ReadLine();
// Using StringBuilder
timeTest.Start();
string reversed = ReverseSB(str);
timeTest.Stop();
Console.WriteLine("Reverse text: {0}\ntime: {1} - StringBuilder class", reversed, timeTest.Elapsed);
timeTest.Reset();
Console.WriteLine();
// Using Array.Reverse
timeTest.Start();
string reversedArrayReverse = ReverseArray(str);
timeTest.Stop();
Console.WriteLine("Reverse text: {0}\ntime: {1} - Array.Reverse", reversedArrayReverse, timeTest.Elapsed);
timeTest.Reset();
Console.WriteLine();
// Using XOR
timeTest.Start();
string reversedXor = ReverseXor(str);
timeTest.Stop();
Console.WriteLine("Reverse text: {0}\ntime: {1} - XOR", reversedXor, timeTest.Elapsed);
timeTest.Reset();
}
示例9: AddLots
public void AddLots()
{
var expression = "X = (((A + B) * (A + B)) * ((A + B) * (A + B))) + (((A + B) * (A + B)) * ((A + B) * (A + B)))";
const int _size = 1000000;
_data = new Dictionary<string, IEnumerable<KeyValuePair<string, Atom>>>
{
{"A", Enumerable.Range(0, _size).Select(i => new KeyValuePair<string,Atom>("", i + .0))},
{"B", Enumerable.Range(_size, _size).Select(i => new KeyValuePair<string,Atom>("", i + .0))},
};
var watch = new Stopwatch();
watch.Reset();
Console.WriteLine("Start sequential...");
watch.Start();
var result2 = ComputeSequential(expression, _size)["X"](new[]{new KeyValuePair<string, Atom>[0]}).Select(item => item.Value).ToArray();
watch.Stop();
Console.WriteLine("Sequential elapsed:{0}", watch.Elapsed);
watch.Reset();
Console.WriteLine("Start parallel...");
watch.Start();
var result = ComputeParallel(expression, _size)["X"](new[]{new KeyValuePair<string, Atom>[0]}).Select(item => item.Value).ToArray();
watch.Stop();
Console.WriteLine("Parallel elapsed:{0}", watch.Elapsed);
CollectionAssert.AreEqual(result, result2);
}
示例10: SetAll
public void SetAll()
{
writeCount = 0;
writeTime = 0;
Stopwatch watch = new Stopwatch();
watch.Reset();
watch.Start();
foreach (var kv in initialData)
if (stopFlag == false)
{
storageToWrite.Set(kv.Key, kv.Value, false);
writeCount += 1;
}
else break;
stopFlag = true;
watch.Stop();
writeTime += (int)watch.ElapsedMilliseconds;
watch.Reset();
watch.Start();
storageToWrite._btreeDb.Sync();
watch.Stop();
syncTime+= (int)watch.ElapsedMilliseconds;
writeTime += (int)watch.ElapsedMilliseconds;
}
示例11: Check_performance
public void Check_performance()
{
var sw = new Stopwatch();
int numIterations = 1000000;
sw.Start();
for (int i = 0; i < numIterations; i++)
{
i.IsMessage();
}
sw.Stop();
Console.WriteLine("Not cached: " + sw.ElapsedMilliseconds);
sw.Reset();
var hashTable = new Dictionary<Type, bool>();
sw.Start();
for (int i = 0; i < numIterations; i++)
{
hashTable[i.GetType()] = i.IsMessage();
}
sw.Stop();
Console.WriteLine("Set dictionary: " + sw.ElapsedMilliseconds);
sw.Reset();
sw.Start();
for (int i = 0; i < numIterations; i++)
{
var r = hashTable[i.GetType()];
}
sw.Stop();
Console.WriteLine("Get dictionary: " + sw.ElapsedMilliseconds);
}
示例12: 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());
}
}
示例13: ComputeTimesPrimes
public void ComputeTimesPrimes()
{
Stopwatch w = new Stopwatch();
w.Start();
PrimeNumbers.GeneratePrimeNumbers1(100000);
Console.WriteLine("Primes 1: " + w.ElapsedMilliseconds.ToString());
w.Stop();
w.Reset();
w.Start();
PrimeNumbers.GeneratePrimeNumbers2(100000);
Console.WriteLine("Primes 2: "+ w.ElapsedMilliseconds.ToString());
w.Stop();
w.Reset();
w.Start();
PrimeNumbers.GeneratePrimeNumbers3(100000);
Console.WriteLine("Primes 3: " + w.ElapsedMilliseconds.ToString());
w.Stop();
w.Start();
for (int i = 1; i <= 100000; i++)
{
int mod = i % 2;
}
w.Stop();
Console.WriteLine("Primes 4: " + w.ElapsedMilliseconds.ToString());
}
示例14: TestProgram
public static void TestProgram()
{
var sw = new Stopwatch();
sw.Start();
Console.WriteLine("Fi(30) = {0} - slow", CalculateNthFi(30));
sw.Stop();
Console.WriteLine("Calculated in {0}", sw.ElapsedMilliseconds);
sw.Reset();
sw.Start();
Console.WriteLine("Fi(30) = {0} - fast", CalculateNthFi2(30));
sw.Stop();
Console.WriteLine("Calculated in {0}", sw.ElapsedMilliseconds);
sw.Reset();
sw.Start();
Console.WriteLine("Fi(30) = {0} - fast2", CalculateNthFi3(30, 0, 1, 1));
sw.Stop();
Console.WriteLine("Calculated in {0}", sw.ElapsedMilliseconds);
Console.WriteLine("");
}
示例15: 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);
}
}