3.1.35

上次更新:2019-04-17
发现了题解错误/代码缺陷/排版问题?请点这里:如何:提交反馈

解答

实验结果:

由于包含重复单词,因此结果会比 4 略低一些。
需要对 FrequencyCounter 做一些修改,令其只取前 n 个单词。

代码

static void Main(string[] args)
{
    int n = 8000;
    int multiplyBy2 = 5;
    int repeatTimes = 5;
    double lastTime = -1;
    Console.WriteLine("n\ttime\tratio");
    for (int i = 0; i < multiplyBy2; i++)
    {
        Console.Write(n + "\t");
        long timeSum = 0;
        for (int j = 0; j < repeatTimes; j++)
        {
            SequentialSearchST<string, int> st = new SequentialSearchST<string, int>();
            Stopwatch 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;
    }
}

另请参阅

SymbolTable 库

上一题 下一题