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] == '-i' and i + 1 < len(sys.argv):
56 in_filename = sys.argv[i]
57 elif sys.argv[i] == '-q':
59 elif sys.argv[i] == '-kakadu':
66 while i < 10 * 1024 * 1024:
70 if out_filename is not None:
71 out_file = open(out_filename, 'wt')
72 out_file.write('filename,iterations,threads,command,comment,time_ms\n')
75 for line in open(in_filename, 'rt').readlines()[1:]:
76 line = line.replace('\n', '')
77 filename, num_iterations, num_threads, command, comment = line.split(',')
78 num_threads = int(num_threads)
79 num_iterations = int(num_iterations)
81 for i in range(num_iterations):
84 if command == 'DECOMPRESS':
85 args = [kdu_expand_path,
87 '-num_threads', str(num_threads),
88 '-o', 'out_perf_test.pgm']
89 elif command == 'COMPRESS':
90 args = [kdu_compress_path,
92 '-num_threads', str(num_threads),
94 '-o', 'out_perf_test.jp2']
100 env['OPJ_NUM_THREADS'] = str(num_threads)
102 env['OPJ_NUM_THREADS'] = '0'
103 if command == 'DECOMPRESS':
104 args = [opj_decompress_path,
105 '-i', filename, '-o', 'out_perf_test.pgm']
106 elif command == 'COMPRESS':
107 args = [opj_compress_path,
108 '-i', filename, '-o', 'out_perf_test.jp2']
110 assert False, command
111 p = subprocess.Popen(args,
112 stdout=subprocess.PIPE,
113 stderr=subprocess.PIPE,
118 if os.path.exists('out_perf_test.pgm'):
119 os.unlink('out_perf_test.pgm')
120 if os.path.exists('out_perf_test.jp2'):
121 os.unlink('out_perf_test.jp2')
122 spent_time = stop - start
123 total_time += spent_time
125 if len(comment) != 0:
126 print('%s (%s), %d iterations, %d threads, %s: %.02f s' %
127 (filename, comment, num_iterations, num_threads,
128 command, spent_time))
130 print('%s, %d iterations, %d threads, %s: %.02f s' %
131 (filename, num_iterations, num_threads, command, spent_time))
132 if out_file is not None:
133 out_file.write('%s,%d,%d,%s,%s,%d\n' %
134 (filename, num_iterations, num_threads, command,
135 comment, spent_time * 1000))
138 print('Total time: %.02f s' % total_time)
139 if out_file is not None:
140 out_file.write('%s,,,,,%d\n' % ('TOTAL', total_time * 1000))