本文整理汇总了C#中System.TimeSpan.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.Sum方法的具体用法?C# TimeSpan.Sum怎么用?C# TimeSpan.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan.Sum方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteSunSpider
private static void ExecuteSunSpider()
{
const string fileName = @"..\..\..\Jint.Tests\SunSpider\Tests\access-fannkuch.js";
var jint = new JintEngine();
#if false
jint.ExecuteFile(fileName);
Console.WriteLine("Attach");
Console.ReadLine();
jint.ExecuteFile(fileName);
#else
jint.ExecuteFile(fileName);
var times = new TimeSpan[20];
int timeOffset = 0;
var lowest = new TimeSpan();
// Perform the iterations.
for (int i = 0; ; i++)
{
long memoryBefore = GC.GetTotalMemory(true);
var stopwatch = Stopwatch.StartNew();
jint.ExecuteFile(fileName);
var elapsed = stopwatch.Elapsed;
long memoryAfter = GC.GetTotalMemory(false);
times[timeOffset++] = elapsed;
if (timeOffset == times.Length)
timeOffset = 0;
if (times[times.Length - 1].Ticks != 0)
{
var average = new TimeSpan(times.Sum(p => p.Ticks) / times.Length);
if (lowest.Ticks == 0 || average.Ticks < lowest.Ticks)
lowest = average;
Console.WriteLine(
"This run: {0}, average: {1}, lowest: {2}, memory usage: {3}",
elapsed.ToString("s\\.fffff"),
average.ToString("s\\.fffff"),
lowest.ToString("s\\.fffff"),
NiceMemory(memoryAfter - memoryBefore)
);
}
}
#endif
}
示例2: TestSecp256k1ElGamalBinaryDoubleAndAdd
public void TestSecp256k1ElGamalBinaryDoubleAndAdd()
{
TimeSpan[] setup_times = new TimeSpan[num_runs];
TimeSpan[] key_generation_times = new TimeSpan[num_runs];
TimeSpan[] encryption_times = new TimeSpan[num_runs];
TimeSpan[] decryption_times = new TimeSpan[num_runs];
for (int i = 0; i < num_runs; i++)
{
var stopwatch = Stopwatch.StartNew();
var curve = CurveFactory.secp256k1;
WeierstrassCurvePoint.Multiplier = new BinaryDoubleAndAddPointMultiplier();
var encoder = new ProbabilisticWeierstrassMessageEncoder(curve, new BigInteger(7));
var encryptor = new ElGamalEncryptor(curve, encoder);
stopwatch.Stop();
var t_setup = stopwatch.Elapsed;
stopwatch.Restart();
var keys = encryptor.GenerateKeyPair();
stopwatch.Stop();
var t_key_generation = stopwatch.Elapsed;
stopwatch.Restart();
var c = encryptor.Encrypt(keys.PublicKey, _m);
stopwatch.Stop();
var t_encryption = stopwatch.Elapsed;
stopwatch.Restart();
var m2 = encryptor.Decrypt(keys.PrivateKey, c);
stopwatch.Stop();
var t_decryption = stopwatch.Elapsed;
var t_total = t_setup + t_key_generation + t_encryption + t_decryption;
Assert.AreEqual(_m, m2);
setup_times[i] = t_setup;
key_generation_times[i] = t_key_generation;
encryption_times[i] = t_encryption;
decryption_times[i] = t_decryption;
}
var setup_avg = setup_times.Sum(x => x.Milliseconds) / (double)num_runs;
var key_generation_avg = key_generation_times.Sum(x => x.Milliseconds) / (double)num_runs;
var encryption_avg = encryption_times.Sum(x => x.Milliseconds) / (double)num_runs;
var decryption_avg = decryption_times.Sum(x => x.Milliseconds) / (double)num_runs;
var total_avg = setup_avg + key_generation_avg + encryption_avg + decryption_avg;
throw new AssertFailedException("Runtime " + total_avg + "(" + key_generation_avg + "," + encryption_avg + "," + decryption_avg + ")");
}
示例3: CalculateAverageTimeSpan
static TimeSpan CalculateAverageTimeSpan(TimeSpan[] timeSpans)
{
double miliseconds = timeSpans.Sum(t => t.TotalMilliseconds) / timeSpans.Length;
return TimeSpan.FromMilliseconds(miliseconds);
}