-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperf_vs_imagick.php
84 lines (67 loc) · 3.1 KB
/
perf_vs_imagick.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
<?php
/**
* Compare performance of GOPP_Image_editor_GS with WP_Image_Editor_Imagick.
* Run from the GS Only PDF Preview plugin directory or your theme's directory.
*/
ini_set( 'ignore_repeated_errors', true );
$basename = basename( __FILE__ );
$dirname = dirname( __FILE__ );
$dirdirname = dirname( $dirname );
error_log( "(===begin " . $basename );
// Hack to work on multi-site.
$_SERVER['HTTP_HOST'] = '192.168.1.64'; // Needs to match DOMAIN_CURRENT_SITE in wp-config.php
$_SERVER['REQUEST_URI'] = preg_replace( '/^\/var\/www(\/[^\/]+\/).+$/', '$1', $dirdirname ); // Needs to match PATH_CURRENT_SITE in wp-config.php
require '../../../wp-load.php';
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
require $dirdirname . '/includes/class-gopp-image-editor-gs.php';
$loop_num = 1; // Warning it's slow!
$pdfs_begin = 0;
$pdfs_end = 5; // Choose to include problematic data or not.
$pdfs = array(
$dirname . '/data/wordpress-gsoc-flyer.pdf', // sRGB color space, no alpha issues.
$dirname . '/data/minimal-us-letter.pdf', // sRGB color space, no alpha issues.
$dirname . '/data/duotone.pdf', // sRGB color space, no alpha issues.
$dirname . '/data/BUDGET 2017.pdf', // sRGB color space, no alpha issues.
$dirname . '/data/SWEBOKv3.pdf', // sRGB color space, no alpha issues.
$dirname . '/data/test_alpha.pdf', // Non-opaque alpha channel.
$dirname . '/data/test_cmyk.pdf', // CMYK color space.
$dirname . '/data/test_cmyk_alpha.pdf', // Non-opaque alpha channel and CMYK color space.
$dirname . '/data/Contents-CR-51-2.pdf', // CMYK color space.
$dirname . '/data/contents-hs-issue-41.pdf', // Non-opaque alpha channel.
$dirname . '/data/kp_sample.pdf', // CMYK color space.
$dirname . '/data/text_graph_image_cmyk_rgb.pdf', // CMYK color space.
);
$cnt_pdfs = count( $pdfs );
$pdfs_end = $cnt_pdfs;
if ( $pdfs_end && $pdfs_end !== $cnt_pdfs ) {
$pdfs = array_slice( $pdfs, $pdfs_begin, $pdfs_end );
}
$tots_g = 0;
$tots_i = 0;
$gs = $imagick = null;
for ( $i = 0; $i < $loop_num; $i++ ) {
foreach ( $pdfs as $pdf ) {
// Do Imagick first as it overwrites previews.
$tots_i += -microtime( true );
$imagick = new WP_Image_Editor_Imagick( $pdf );
$imagick->load();
$imagick->save( $pdf, 'image/jpeg' );
$tots_i += microtime( true );
unset( $imagick );
$tots_g += -microtime( true );
$gs = new GOPP_Image_Editor_GS( $pdf );
$gs->load();
$gs->save( $pdf, 'image/jpeg' );
$tots_g += microtime( true );
unset( $gs );
}
}
error_log( "loop_num=$loop_num, cnt_pdfs=$cnt_pdfs, pdfs=" . implode( ',', $pdfs ) );
error_log( " g=" . sprintf( '%.10f', $tots_g ) );
error_log( " i=" . sprintf( '%.10f', $tots_i ) );
error_log( " g:i=" . sprintf( '%.10f', $tots_i ? $tots_g / $tots_i : 0 ) );
error_log( " i:g=" . sprintf( '%.10f', $tots_g ? $tots_i / $tots_g : 0 ) );
error_log( " avg g=" . sprintf( '%.10f', ( $loop_num * $cnt_pdfs ) ? $tots_g / ( $loop_num * $cnt_pdfs ) : 0 ) );
error_log( " avg i=" . sprintf( '%.10f', ( $loop_num * $cnt_pdfs ) ? $tots_i / ( $loop_num * $cnt_pdfs ) : 0 ) );
error_log( ")===end " . $basename );