-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFilegetTest.php
More file actions
54 lines (47 loc) · 1.34 KB
/
Copy pathFilegetTest.php
File metadata and controls
54 lines (47 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Created by PhpStorm.
* User: shixi_qingzhe
* Date: 18/5/27
* Time: 上午11:00
*/
use PHPUnit\Framework\TestCase;
final class FilegetTest extends TestCase
{
private $reTryTime = 100;
public function testFopen()
{
$timer = Benchmark::getInstance();
$testAVG = $timer -> tryManyTimes(function () {
$f = fopen(__DIR__.'/file/test', 'r');
$fc = fread($f, filesize(__DIR__.'/file/test'));
$fct = strlen($fc);
fclose($f);
},$this -> reTryTime);
echo "fopen + fclose = {$testAVG} \n";
}
public function testFgct()
{
$timer = Benchmark::getInstance();
$testAVG = $timer -> tryManyTimes(function () {
$fc = file_get_contents(__DIR__.'/file/test');
$fu = strlen($fc);
}, $this -> reTryTime);
echo "f get ctx = {$testAVG} \n";
}
public function testFgets() // 逐行读取数据
{
$timer = Benchmark::getInstance();
$testAVG = $timer -> tryManyTimes(function () {
$f = fopen(__DIR__.'/file/test', 'r');
$fc = "";
if($f){
while(!feof($f)) {
$fc .= fgets($f);
}
}
$fcc = strlen($fc);
}, $this -> reTryTime);
echo "fgets = {$testAVG} \n";
}
}