DiffMatchPatch\PerformanceTest::testDiffMainMemoryLeaks PHP Method

testDiffMainMemoryLeaks() public method

    public function testDiffMainMemoryLeaks()
    {
        $text1 = file_get_contents(__DIR__ . '/fixtures/S_performance1.txt');
        $text2 = file_get_contents(__DIR__ . '/fixtures/S_performance2.txt');
        $n = 20;
        // Warm up
        $diff = new Diff();
        $diff->setTimeout(0);
        $diff->main($text1, $text2);
        unset($diff);
        $timeStart = microtime(1);
        $memoryStart = memory_get_usage();
        for ($i = 0; $i < $n; $i++) {
            $diff = new Diff();
            $diff->setTimeout(0);
            $diff->main($text1, $text2);
            unset($diff);
        }
        $timeElapsed = microtime(1) - $timeStart;
        $memoryUsage = (memory_get_usage() - $memoryStart) / 1024 / 1024;
        $this->assertLessThan(0.001, $memoryUsage);
        echo 'Elapsed time: ' . round($timeElapsed, 3) . PHP_EOL;
        echo 'Memory usage: ' . round($memoryUsage, 10) . PHP_EOL;
    }