2 # -*- coding: utf-8 -*-
4 # Copyright (c) 2017, IntoPIX SA
5 # Contact: support@intopix.com
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
37 print('Usage: perf_test.py [-kakadu] [-i filelist.csv] [-o out.csv] [-q]')
40 opj_decompress_path = 'opj_decompress'
41 opj_compress_path = 'opj_compress'
42 kdu_expand_path = 'kdu_expand'
43 kdu_compress_path = 'kdu_compress'
45 in_filename = 'perf_test_filelist.csv'
50 while i < len(sys.argv):
51 if sys.argv[i] == '-o' and i + 1 < len(sys.argv):
53 out_filename = sys.argv[i]
54 elif sys.argv[i] == '-q':
56 elif sys.argv[i] == '-kakadu':
63 while i < 10 * 1024 * 1024:
67 if out_filename is not None:
68 out_file = open(out_filename, 'wt')
69 out_file.write('filename,iterations,threads,command,comment,time_ms\n')
72 for line in open(in_filename, 'rt').readlines()[1:]:
73 line = line.replace('\n', '')
74 filename, num_iterations, num_threads, command, comment = line.split(',')
75 num_threads = int(num_threads)
76 num_iterations = int(num_iterations)
78 for i in range(num_iterations):
81 if command == 'DECOMPRESS':
82 args = [kdu_expand_path,
84 '-num_threads', str(num_threads),
85 '-o', 'out_perf_test.pgm']
86 elif command == 'COMPRESS':
87 args = [kdu_compress_path,
89 '-num_threads', str(num_threads),
91 '-o', 'out_perf_test.jp2']
97 env['OPJ_NUM_THREADS'] = str(num_threads)
99 env['OPJ_NUM_THREADS'] = '0'
100 if command == 'DECOMPRESS':
101 args = [opj_decompress_path,
102 '-i', filename, '-o', 'out_perf_test.pgm']
103 elif command == 'COMPRESS':
104 args = [opj_compress_path,
105 '-i', filename, '-o', 'out_perf_test.jp2']
107 assert False, command
108 p = subprocess.Popen(args,
109 stdout=subprocess.PIPE,
110 stderr=subprocess.PIPE,
115 if os.path.exists('out_perf_test.pgm'):
116 os.unlink('out_perf_test.pgm')
117 if os.path.exists('out_perf_test.jp2'):
118 os.unlink('out_perf_test.jp2')
119 spent_time = stop - start
120 total_time += spent_time
122 if len(comment) != 0:
123 print('%s (%s), %d iterations, %d threads, %s: %.02f s' %
124 (filename, comment, num_iterations, num_threads,
125 command, spent_time))
127 print('%s, %d iterations, %d threads, %s: %.02f s' %
128 (filename, num_iterations, num_threads, command, spent_time))
129 if out_file is not None:
130 out_file.write('%s,%d,%d,%s,%s,%d\n' %
131 (filename, num_iterations, num_threads, command,
132 comment, spent_time * 1000))
135 print('Total time: %.02f s' % total_time)
136 if out_file is not None:
137 out_file.write('%s,,,,,%d\n' % ('TOTAL', total_time * 1000))