-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathstreaming-bench.php
executable file
·131 lines (108 loc) · 3.81 KB
/
streaming-bench.php
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env php
<?php
use Jcupitt\Vips\Config;
use Jcupitt\Vips\Image;
use Jcupitt\Vips\Source;
use Jcupitt\Vips\SourceResource;
use Jcupitt\Vips\Target;
use Jcupitt\Vips\TargetResource;
require dirname(__DIR__) . '/vendor/autoload.php';
$doBenchmark = static function () {
$sourceOptions = ['access' => 'sequential'];
$sourceOptionString = 'access=sequential';
$iterations = 100;
$targetWidth = 100.0;
$targetSuffix = '.jpg';
$targetOptions = ['optimize-coding' => true, 'strip' => true, 'Q' => 100, 'profile' => 'srgb'];
$targetFile = dirname(__DIR__) . "/tests/images/target.jpg";
$sourceFile = dirname(__DIR__) . '/tests/images/img_0076.jpg';
### Callbacks
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$source = new SourceResource(fopen($sourceFile, 'rb'));
$target = new TargetResource(fopen($targetFile, 'wb+'));
$image = Image::newFromSource($source, '', $sourceOptions);
$image = $image->resize($targetWidth / $image->width);
$image->writeToTarget(
$target,
$targetSuffix,
$targetOptions
);
unlink($targetFile);
}
echo (microtime(true) - $start) . ' Seconds for Streaming with callbacks' . PHP_EOL;
### Builtin
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$source = Source::newFromFile($sourceFile);
$target = Target::newToFile($targetFile);
$image = Image::newFromSource($source, '', $sourceOptions);
$image = $image->resize($targetWidth / $image->width);
$image->writeToTarget(
$target,
$targetSuffix,
$targetOptions
);
unlink($targetFile);
}
echo (microtime(true) - $start) . ' Seconds for Streaming with builtin source/target' . PHP_EOL;
### Callbacks Thumbnail
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$source = new SourceResource(fopen($sourceFile, 'rb'));
$target = new TargetResource(fopen($targetFile, 'wb+'));
$image = Image::thumbnail_source($source, $targetWidth);
$image->writeToTarget(
$target,
$targetSuffix,
$targetOptions
);
unlink($targetFile);
}
echo (microtime(true) - $start) . ' Seconds for Streaming Thumbnail with callbacks' . PHP_EOL;
### Builtin Thumbnail
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$source = Source::newFromFile($sourceFile);
$target = Target::newToFile($targetFile);
$image = Image::thumbnail_source($source, $targetWidth);
$image->writeToTarget(
$target,
$targetSuffix,
$targetOptions
);
unlink($targetFile);
}
echo (microtime(true) - $start) . ' Seconds for Streaming Thumbnail with builtin source/target' . PHP_EOL;
### Thumbnail
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$image = Image::thumbnail($sourceFile . "[$sourceOptionString]", $targetWidth);
$image->writeToFile(
$targetFile,
$targetOptions
);
unlink($targetFile);
}
echo (microtime(true) - $start) . ' Seconds for Thumbnail API' . PHP_EOL;
### Classic
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$image = Image::newFromFile($sourceFile, $sourceOptions);
$image = $image->resize($targetWidth / $image->width);
$image->writeToFile(
$targetFile,
$targetOptions
);
unlink($targetFile);
}
echo (microtime(true) - $start) . ' Seconds for Classic API' . PHP_EOL;
};
$doBenchmark();
//echo "=== NOW NO CACHE ===" . PHP_EOL;
//
//Config::cacheSetMax(0);
//Config::cacheSetMaxFiles(0);
//Config::cacheSetMaxMem(0);
//
//$doBenchmark();