3.1.35 #
解答 #
实验结果:
由于包含重复单词,因此结果会比 4 略低一些。
需要对 FrequencyCounter
做一些修改,令其只取前 n 个单词。
代码 #
var n = 8000;
var multiplyBy2 = 5;
var repeatTimes = 5;
double lastTime = -1;
Console.WriteLine("n\ttime\tratio");
for (var i = 0; i < multiplyBy2; i++)
{
Console.Write(n + "\t");
long timeSum = 0;
for (var j = 0; j < repeatTimes; j++)
{
var st = new SequentialSearchSt<string, int>();
var sw = Stopwatch.StartNew();
FrequencyCounter.MostFrequentlyWord("tale.txt", n, 0, st);
sw.Stop();
timeSum += sw.ElapsedMilliseconds;
}
timeSum /= repeatTimes;
Console.Write(timeSum + "\t");
if (lastTime < 0)
Console.WriteLine("--");
else
Console.WriteLine(timeSum / lastTime);
lastTime = timeSum;
n *= 2;
}