本文整理汇总了C#中System.Diagnostics.Stopwatch.Restart方法的典型用法代码示例。如果您正苦于以下问题:C# System.Diagnostics.Stopwatch.Restart方法的具体用法?C# System.Diagnostics.Stopwatch.Restart怎么用?C# System.Diagnostics.Stopwatch.Restart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Stopwatch
的用法示例。
在下文中一共展示了System.Diagnostics.Stopwatch.Restart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
private static void Search(int collectionSize, int searchItemsCount)
{
Console.WriteLine($"V množině o velikost {collectionSize:n0} hledáno {searchItemsCount:n0}x:");
#region Sample data
var sw = new System.Diagnostics.Stopwatch();
var list = new List<Guid>();
var dictionary = new Dictionary<Guid, object>();
foreach (var guid in Enumerable.Range(0, collectionSize).Select(g => Guid.NewGuid()))
{
list.Add(guid);
dictionary.Add(guid, null);
}
var lookup = list.ToLookup(i => i);
var sortedArray = list.ToArray();
Array.Sort(sortedArray);
// vytvoření sample-dat, které budeme hledat
var rand = new Random();
var hledane = Enumerable.Range(0, searchItemsCount).Select(g => (rand.NextDouble() > 0.5) ? Guid.NewGuid() : list[rand.Next(list.Count)]).ToList();
#endregion
// Contains = sekvenční vyhledávání = O(n)
sw.Start();
int found = hledane.Count(t => list.Contains(t));
sw.Stop();
Console.WriteLine($"\tList<>.Contains(): Nalezeno {found:n0}x, čas {sw.ElapsedTicks,10:n0} ticks");
// binární půlení = O(log(n))
sw.Restart();
found = hledane.Count(t => Array.BinarySearch<Guid>(sortedArray, t) >= 0);
sw.Stop();
Console.WriteLine($"\tArray.BinarySearch<>(): Nalezeno {found:n0}x, čas {sw.ElapsedTicks,10:n0} ticks");
// Dictionary = Hashtable, O(1)
sw.Restart();
found = hledane.Count(t => dictionary.ContainsKey(t));
sw.Stop();
Console.WriteLine($"\tDictionary<>.ContainsKey(): Nalezeno {found:n0}x, čas {sw.ElapsedTicks,10:n0} ticks");
// Dictionary = Hashtable, O(1)
sw.Restart();
found = hledane.Count(i => lookup.Contains(i));
sw.Stop();
Console.WriteLine($"\tLINQ ILookup: Nalezeno {found:n0}x, čas {sw.ElapsedTicks,10:n0} ticks");
Console.WriteLine();
}
示例2: WorkerEvents
static private void WorkerEvents()
{
Tuple<EventDelegate, IPlugin> cEvent;
System.Diagnostics.Stopwatch cWatch = new System.Diagnostics.Stopwatch();
while (true)
{
try
{
cEvent = _aqEvents.Dequeue();
cWatch.Reset();
cWatch.Restart();
cEvent.Item1(cEvent.Item2);
cWatch.Stop();
if (40 < cWatch.ElapsedMilliseconds)
(new Logger()).WriteDebug3("duration: " + cWatch.ElapsedMilliseconds + " queue: " + _aqEvents.nCount);
if (0 < _aqEvents.nCount)
(new Logger()).WriteDebug3(" queue: " + _aqEvents.nCount);
}
catch (System.Threading.ThreadAbortException)
{
break;
}
catch (Exception ex)
{
(new Logger()).WriteError(ex);
}
}
}
示例3: SolveInstance
protected override void SolveInstance(IGH_DataAccess DA)
{
// Indata
WR_Structure structure = null;
bool go = false;
List<int> modes = new List<int>();
double sFac = 0;
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
if (!DA.GetData(0, ref structure)) { return; }
if (!DA.GetData(1, ref go)) { return; }
if (!DA.GetDataList(2, modes)) { return; }
if (!DA.GetData(3, ref sFac)) { return; }
if (go)
{
_resElems = new List<ResultElement>();
_log.Clear();
watch.Restart();
// Solve
WR_ModeShapeOptimizer optimizer = new WR_ModeShapeOptimizer(structure);
watch.Stop();
_log.Add(String.Format("Initialising: {0}ms", watch.ElapsedMilliseconds));
watch.Restart();
//Run
optimizer.Run(modes, sFac);
watch.Stop();
_log.Add(String.Format("Run mode shape optimization: {0}ms", watch.ElapsedMilliseconds));
watch.Restart();
// Extract results
List<WR_IElement> elems = structure.GetAllElements();
for (int i = 0; i < elems.Count; i++)
{
if (elems[i] is WR_Element3d)
{
WR_Element3d el3d = (WR_Element3d)elems[i];
ResultElement re = new ResultElement(el3d);
_resElems.Add(re);
}
}
watch.Stop();
_log.Add(String.Format("Extract results: {0}ms", watch.ElapsedMilliseconds));
}
DA.SetDataList(0, _log);
DA.SetDataList(1, _resElems);
}
示例4: Main
static void Main(string[] args) {
var stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Restart();
run();
stopWatch.Stop();
Console.WriteLine(string.Format("Elapsed Time: {0:0.000} seconds", stopWatch.Elapsed.TotalSeconds));
}
示例5: WorkerEvents
static private void WorkerEvents()
{
Tuple<EventDelegate, Effect, Effect> cEvent;
System.Diagnostics.Stopwatch cWatch = new System.Diagnostics.Stopwatch();
while (true)
{
try
{
cEvent = _aqEvents.Dequeue();
cWatch.Reset();
cWatch.Restart();
cEvent.Item1(cEvent.Item2, cEvent.Item3);
(new Logger()).WriteDebug3("event sended [hc = " + cEvent.Item3.GetHashCode() + "][" + cEvent.Item1.Method.Name + "]");
cWatch.Stop();
if (40 < cWatch.ElapsedMilliseconds)
(new Logger()).WriteDebug3("duration: " + cWatch.ElapsedMilliseconds + " queue: " + _aqEvents.nCount);
if (0 < _aqEvents.nCount)
(new Logger()).WriteDebug3(" queue: " + _aqEvents.nCount);
}
catch (System.Threading.ThreadAbortException)
{
break;
}
catch (Exception ex)
{
(new Logger()).WriteError(ex);
}
}
}
示例6: Main1
public static void Main1()
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
string path = "../../../Databases/";
int NumberOfRecords = 1000000;
Random rnd = new Random();
Console.WriteLine("Start Universal Index");
PType tp_table_element = new PTypeRecord(
new NamedType("name", new PType(PTypeEnumeration.sstring)),
new NamedType("age", new PType(PTypeEnumeration.integer)));
IBearingTableImmutable table = new TableViewImmutable(path + "table", tp_table_element);
sw.Restart();
bool tobuild = false;
if (tobuild)
{
table.Fill(Enumerable.Range(0, NumberOfRecords).Select(i =>
(object)(new object[] {i.ToString(), i == NumberOfRecords/2 ? -1 : i})));
sw.Stop();
Console.WriteLine("Load Table of {0} elements ok. Duration {1}", NumberOfRecords, sw.ElapsedMilliseconds);
}
IIndexImmutable<string> s_index = new IndexViewImmutable<string>(path + "s_index")
{
Table = (IBearingTable) table,
KeyProducer = va => (string)((object[])va)[0]
};
if (tobuild)
{
sw.Restart();
s_index.Build();
sw.Stop();
Console.WriteLine("s_index Build ok. Duration {0}", sw.ElapsedMilliseconds);
}
sw.Restart();
int cnt = 0;
for (int i = 0; i < 1000; i++)
{
int c = s_index.GetAllByKey(rnd.Next(NumberOfRecords - 1).ToString()).Count();
if (c > 1) Console.WriteLine("Unexpected Error: {0}", c);
cnt += c;
}
sw.Stop();
Console.WriteLine("1000 GetAllByKey ok. Duration={0} cnt={1}", sw.ElapsedMilliseconds, cnt);
}
示例7: Main
static void Main(string[] args)
{
LinkedList<int> list = new LinkedList<int>();
int i = 1;
while (i <= 100000)
{
list.AddLast(i);
i++;
}
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
Console.WriteLine("Measurements in ticks");
int loopsCounter;
#region foreach
loopsCounter = 0;
timer.Restart();
foreach (int j in list)
{
loopsCounter++;
int x = j;
}
timer.Stop();
Console.WriteLine("{0,-8}: {1,8} (items count: {2})", "foreach", timer.ElapsedTicks, loopsCounter);
#endregion
#region nodes
loopsCounter = 0;
timer.Restart();
LinkedListNode<int> node = list.First;
while (node != null)
{
loopsCounter++;
int y = node.Value;
node = node.Next;
}
timer.Stop();
Console.WriteLine("{0,-8}: {1,8} (items count: {2})", "nodes", timer.ElapsedTicks, loopsCounter);
#endregion
Console.ReadLine();
}
示例8: TestBasicLineSymbolizer
public void TestBasicLineSymbolizer()
{
var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\roads.shp", false);
var l = new SharpMap.Layers.VectorLayer("roads", p);
//l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5);
l.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1);
l.Style.EnableOutline = false;
var m = new SharpMap.Map(new System.Drawing.Size(1440,1080)) {BackColor = System.Drawing.Color.Cornsilk};
m.Layers.Add(l);
m.ZoomToExtents();
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
m.GetMap();
sw.Stop();
System.Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
sw.Restart();
var bmp = m.GetMap();
sw.Stop();
System.Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("NDSRoads1.bmp");
var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer();
//cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) });
cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1) });
l.Style.LineSymbolizer = cls;
sw.Restart();
bmp = m.GetMap();
sw.Stop();
System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("NDSRoads2.bmp");
}
示例9: Execute
public void Execute()
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Restart();
try
{
OnExecute();
}
catch(Exception e)
{
LastError = e;
}
sw.Stop();
UserTime = sw.Elapsed.TotalMilliseconds;
}
示例10: TestPlainPolygonSymbolizer
public void TestPlainPolygonSymbolizer()
{
var provider = new SharpMap.Data.Providers.ShapeFile(
"..\\..\\..\\WinFormSamples\\GeoData\\World\\countries.shp", true);
var l = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer("Countries", provider);
l.Symbolizer = new ModifiedBasicPolygonSymbolizer
{
Fill = new System.Drawing.Drawing2D.HatchBrush(
System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal,
System.Drawing.Color.Red /*,
System.Drawing.Color.LightPink*/),
UseClipping = false,
//Outline = System.Drawing.Pens.AliceBlue
};
var m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.Cornsilk };
m.Layers.Add(l);
m.ZoomToExtents();
var sw = new System.Diagnostics.Stopwatch();
var img = m.GetMap();
sw.Start();
img = m.GetMap();
img.Save("PolygonSymbolizer-1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
sw.Stop();
System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds));
l.Symbolizer = new SharpMap.Rendering.Symbolizer.BasicPolygonSymbolizer()
{
Fill = new System.Drawing.Drawing2D.HatchBrush(
System.Drawing.Drawing2D.HatchStyle.WideDownwardDiagonal,
System.Drawing.Color.Red/*,
System.Drawing.Color.LightPink*/),
UseClipping = false,
//Outline = System.Drawing.Pens.AliceBlue
};
sw.Restart();
img = m.GetMap();
img.Save("PolygonSymbolizer-2.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
sw.Stop();
System.Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds));
}
示例11: Main
static void Main(string[] args)
{
var context = new SoftUniEntities();
var totalCount = context.Employees.Count();
var stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
var names = GetNamesWithNativeQuery(context);
stopWatch.Stop();
Console.WriteLine("Native: {0}", stopWatch.Elapsed);
//Console.WriteLine(string.Join(", ", names));
stopWatch.Restart();
var names2 = GetNamesWithLinqQuery(context);
stopWatch.Stop();
Console.WriteLine("Linq: {0}", stopWatch.Elapsed);
//Console.WriteLine(string.Join(", ", names2));
}
示例12: TryJaggedArraySpeed
public void TryJaggedArraySpeed()
{
int[][] jaggedArray;
var sw = new System.Diagnostics.Stopwatch();
for (int iterations = 0; iterations < Iterations; iterations++)
{
jaggedArray = new int[2][];
for (int i = 0; i < 2; i++)
{
jaggedArray[i] = new int[3];
}
}
TestContext.WriteLine("jagged creation: " + sw.Elapsed);
jaggedArray = new int[2][];
for (int i = 0; i < 2; i++)
{
jaggedArray[i] = new int[3];
}
TestContext.WriteLine("jaggedArray rank:" + jaggedArray.Rank);
sw.Restart();
for (int iterations = 0; iterations < Iterations; iterations++)
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
{
int tmp = jaggedArray[i][j];
jaggedArray[i][j] = i * j;
}
TestContext.WriteLine("jagged array access & replace time: " + sw.Elapsed);
}
示例13: SpeedTest
public void SpeedTest()
{
string dsdPath = Utility.GetPath("lib\\StructureSample.xml");
const int smallLoopCount = 1;
const int bigLoopCount = 1000;
var list = new List<decimal>();
var list2 = new List<TimeSpan>();
for (int i = 0; i < bigLoopCount; i++)
{
var stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
for (int j = 0; j < smallLoopCount; j++)
{
using (var reader = XmlReader.Create(dsdPath))
{
while (reader.Read())
{ }
}
}
stopWatch.Stop();
long ticks = stopWatch.ElapsedTicks;
stopWatch.Restart();
for (int k = 0; k < smallLoopCount; k++)
{
var message = StructureMessage.Load(dsdPath);
}
stopWatch.Stop();
Console.Write((decimal)stopWatch.ElapsedTicks / ticks);
list.Add((decimal)stopWatch.ElapsedTicks / ticks);
list2.Add(stopWatch.Elapsed);
Console.WriteLine(" : {0}", stopWatch.Elapsed);
}
Console.WriteLine("Average: {0}", list.Average());
Console.WriteLine("Average Time: {0}", TimeSpan.FromTicks((long)list2.Select(i => i.Ticks).Average()));
}
示例14: GetAR
///<summary>Only one dimension to the list for now.</summary>
public static List<List<int>> GetAR(DateTime dateFrom,DateTime dateTo,List<DashboardAR> listDashAR) {
if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
return Meth.GetObject<List<List<int>>>(MethodBase.GetCurrentMethod(),dateFrom,dateTo,listDashAR);
}
//assumes that dateFrom is the first of the month and that there are 12 periods
//listDashAR may be empty, in which case, this routine will take about 18 seconds, but the user was warned.
//listDashAR may also me incomplete, especially the most recent month(s).
string command;
List<int> listInt;
listInt=new List<int>();
bool agingWasRun=false;
#if DEBUG
_elapsedTimeAR="";
System.Diagnostics.Stopwatch stopWatch=new System.Diagnostics.Stopwatch();
System.Diagnostics.Stopwatch stopWatchTotal=new System.Diagnostics.Stopwatch();
_elapsedTimeAR="Elapsed time for GetAR:\r\n";
stopWatch.Restart();
stopWatchTotal.Restart();
#endif
for(int i=0;i<12;i++) {
DateTime dateLastOfMonth=dateFrom.AddMonths(i+1).AddDays(-1);
DashboardAR dash=null;
for(int d=0;d<listDashAR.Count;d++) {
if(listDashAR[d].DateCalc!=dateLastOfMonth) {
continue;
}
dash=listDashAR[d];
}
if(dash!=null) {//we found a DashboardAR object from the database for this month, so use it.
listInt.Add((int)dash.BalTotal);
continue;
}
agingWasRun=true;
#if DEBUG
stopWatch.Restart();
#endif
//run historical aging on all patients based on the date entered.
Ledgers.ComputeAging(0,dateLastOfMonth,true);
[email protected]"SELECT SUM(Bal_0_30+Bal_31_60+Bal_61_90+BalOver90),SUM(InsEst) FROM patient";
DataTable table=Db.GetTable(command);
#if DEBUG
stopWatch.Stop();
_elapsedTimeAR+="Ledgers.ComputeAging() #"+i+" : "+stopWatch.Elapsed.ToString()+"\r\n";
stopWatch.Restart();
#endif
dash=new DashboardAR();
dash.DateCalc=dateLastOfMonth;
dash.BalTotal=PIn.Double(table.Rows[0][0].ToString());
dash.InsEst=PIn.Double(table.Rows[0][1].ToString());
DashboardARs.Insert(dash);//save it to the db for later.
listInt.Add((int)dash.BalTotal);//and also use it now.
}
if(agingWasRun) {
#if DEBUG
stopWatch.Restart();
#endif
Ledgers.RunAging();//set aging back to normal
#if DEBUG
stopWatch.Stop();
_elapsedTimeAR+="set aging back to normal: "+stopWatch.Elapsed.ToString()+"\r\n";
stopWatch.Restart();
#endif
}
#if DEBUG
stopWatch.Stop();
stopWatchTotal.Stop();
_elapsedTimeAR+="Total: "+stopWatchTotal.Elapsed.ToString();
if(_showElapsedTimesForDebug) {
System.Windows.Forms.MessageBox.Show(_elapsedTimeAR);
}
#endif
List<List<int>> retVal=new List<List<int>>();
retVal.Add(listInt);
return retVal;
}
示例15: GetProvList
public static DataTable GetProvList(DateTime dt) {
if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
return Meth.GetTable(MethodBase.GetCurrentMethod(),dt);
}
#if DEBUG
_elapsedTimeProvList="";
System.Diagnostics.Stopwatch stopWatch=new System.Diagnostics.Stopwatch();
System.Diagnostics.Stopwatch stopWatchTotal=new System.Diagnostics.Stopwatch();
_elapsedTimeProvList="Elapsed time for GetProvList:\r\n";
stopWatch.Restart();
stopWatchTotal.Restart();
#endif
Random rnd=new Random();
string rndStr=rnd.Next(1000000).ToString();
string command;
command="DROP TABLE IF EXISTS tempdash"[email protected]";";
Db.NonQ(command);
#if DEBUG
stopWatch.Stop();
_elapsedTimeProvList+="DROP TABLE: "+stopWatch.Elapsed.ToString()+"\r\n";
stopWatch.Restart();
#endif
[email protected]"CREATE TABLE tempdash"[email protected]" (
ProvNum bigint NOT NULL PRIMARY KEY,
production decimal NOT NULL,
income decimal NOT NULL
) DEFAULT CHARSET=utf8";
Db.NonQ(command);
#if DEBUG
stopWatch.Stop();
_elapsedTimeProvList+="CREATE TABLE: "+stopWatch.Elapsed.ToString()+"\r\n";
stopWatch.Restart();
#endif
//providers
[email protected]"INSERT INTO tempdash"[email protected]" (ProvNum)
SELECT ProvNum
FROM provider WHERE IsHidden=0
ORDER BY ItemOrder";
Db.NonQ(command);
#if DEBUG
stopWatch.Stop();
_elapsedTimeProvList+="providers: "+stopWatch.Elapsed.ToString()+"\r\n";
stopWatch.Restart();
#endif
//production--------------------------------------------------------------------
//procs
[email protected]"UPDATE tempdash"[email protected]"
SET production=(SELECT SUM(ProcFee*(UnitQty+BaseUnits)) FROM procedurelog
WHERE procedurelog.ProvNum=tempdash"[email protected]".ProvNum
AND procedurelog.ProcStatus="+POut.Int((int)ProcStat.C)[email protected]"
AND ProcDate="+POut.Date(dt)+")";
Db.NonQ(command);
#if DEBUG
stopWatch.Stop();
_elapsedTimeProvList+="production - procs: "+stopWatch.Elapsed.ToString()+"\r\n";
stopWatch.Restart();
#endif
//capcomplete writeoffs were skipped
//adjustments
[email protected]"UPDATE tempdash"[email protected]"
SET production=production+(SELECT IFNULL(SUM(AdjAmt),0) FROM adjustment
WHERE adjustment.ProvNum=tempdash"[email protected]".ProvNum
AND AdjDate="+POut.Date(dt)+")";
Db.NonQ(command);
#if DEBUG
stopWatch.Stop();
_elapsedTimeProvList+="production - adjustments: "+stopWatch.Elapsed.ToString()+"\r\n";
stopWatch.Restart();
#endif
//insurance writeoffs
if(PrefC.GetBool(PrefName.ReportsPPOwriteoffDefaultToProcDate)) {//use procdate
[email protected]"UPDATE tempdash"[email protected]"
SET production=production-(SELECT IFNULL(SUM(WriteOff),0) FROM claimproc
WHERE claimproc.ProvNum=tempdash"[email protected]".ProvNum
AND ProcDate="+POut.Date(dt)[email protected]"
AND (claimproc.Status=1 OR claimproc.Status=4 OR claimproc.Status=0) )";//received or supplemental or notreceived
}
else {
[email protected]"UPDATE tempdash"[email protected]"
SET production=production-(SELECT IFNULL(SUM(WriteOff),0) FROM claimproc
WHERE claimproc.ProvNum=tempdash"[email protected]".ProvNum
AND DateCP="+POut.Date(dt)[email protected]"
AND (claimproc.Status=1 OR claimproc.Status=4) )";//received or supplemental
}
Db.NonQ(command);
#if DEBUG
stopWatch.Stop();
_elapsedTimeProvList+="production - writeoffs: "+stopWatch.Elapsed.ToString()+"\r\n";
stopWatch.Restart();
#endif
//income------------------------------------------------------------------------
//patient income
[email protected]"UPDATE tempdash"[email protected]"
SET income=(SELECT SUM(SplitAmt) FROM paysplit
WHERE paysplit.ProvNum=tempdash"[email protected]".ProvNum
AND DatePay="+POut.Date(dt)+")";
Db.NonQ(command);
#if DEBUG
stopWatch.Stop();
_elapsedTimeProvList+="income - patient: "+stopWatch.Elapsed.ToString()+"\r\n";
//.........这里部分代码省略.........