OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Swarming Authors. All rights reserved. | 2 # Copyright 2013 The Swarming Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 that | 3 # Use of this source code is governed under the Apache License, Version 2.0 that |
4 # can be found in the LICENSE file. | 4 # can be found in the LICENSE file. |
5 | 5 |
6 """Profiler to compare various compression levels with regards to speed | 6 """Profiler to compare various compression levels with regards to speed |
7 and final size when compressing the full set of files from a given | 7 and final size when compressing the full set of files from a given |
8 isolated file. | 8 isolated file. |
9 """ | 9 """ |
10 | 10 |
11 import bz2 | 11 import bz2 |
12 import optparse | 12 import optparse |
13 import os | 13 import os |
14 import shutil | |
15 import subprocess | 14 import subprocess |
16 import sys | 15 import sys |
17 import tempfile | 16 import tempfile |
18 import time | 17 import time |
19 import zlib | 18 import zlib |
20 | 19 |
21 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 20 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
22 sys.path.insert(0, ROOT_DIR) | 21 sys.path.insert(0, ROOT_DIR) |
23 | 22 |
| 23 from third_party.depot_tools import fix_encoding |
| 24 from utils import file_path |
24 from utils import tools | 25 from utils import tools |
25 | 26 |
26 | 27 |
27 def zip_file(compressor_constructor, compression_level, filename): | 28 def zip_file(compressor_constructor, compression_level, filename): |
28 compressed_size = 0 | 29 compressed_size = 0 |
29 compressor = compressor_constructor(compression_level) | 30 compressor = compressor_constructor(compression_level) |
30 with open(filename, 'rb') as f: | 31 with open(filename, 'rb') as f: |
31 while True: | 32 while True: |
32 chunk = f.read(16 * 1024) | 33 chunk = f.read(16 * 1024) |
33 if not chunk: | 34 if not chunk: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 else: | 110 else: |
110 print('Number of files: %s' % len(file_set)) | 111 print('Number of files: %s' % len(file_set)) |
111 print('Total size: %s' % sum(file_set.itervalues())) | 112 print('Total size: %s' % sum(file_set.itervalues())) |
112 | 113 |
113 # Profile! | 114 # Profile! |
114 profile_compress('zlib', zlib.compressobj, range(10), zip_directory, | 115 profile_compress('zlib', zlib.compressobj, range(10), zip_directory, |
115 temp_dir) | 116 temp_dir) |
116 profile_compress('bz2', bz2.BZ2Compressor, range(1, 10), zip_directory, | 117 profile_compress('bz2', bz2.BZ2Compressor, range(1, 10), zip_directory, |
117 temp_dir) | 118 temp_dir) |
118 finally: | 119 finally: |
119 shutil.rmtree(temp_dir) | 120 file_path.rmtree(temp_dir) |
120 | 121 |
121 | 122 |
122 if __name__ == '__main__': | 123 if __name__ == '__main__': |
| 124 fix_encoding.fix_encoding() |
123 sys.exit(main()) | 125 sys.exit(main()) |
OLD | NEW |