MCPcopy
hub / github.com/borgbackup/borg / do_benchmark_cpu

Method do_benchmark_cpu

src/borg/archiver/benchmark_cmd.py:163–348  ·  view source on GitHub ↗

Benchmark CPU-bound operations.

(self, args)

Source from the content-addressed store, hash-verified

161 print(fmt % ("D", msg, total_size_MB / dt_delete, count, file_size_formatted, content, dt_delete))
162
163 def do_benchmark_cpu(self, args):
164 """Benchmark CPU-bound operations."""
165 from timeit import timeit
166
167 result = {} if args.json else None
168
169 is_test = "_BORG_BENCHMARK_CPU_TEST" in os.environ
170 # Use minimal iterations and data size in test mode to keep CI fast.
171 number_default = 1 if is_test else 100
172 number_compression = 1 if is_test else 10
173 number_kdf = 1 if is_test else 5
174 data_size = 100 * 1000 if is_test else 10 * 1000 * 1000
175
176 random_10M = os.urandom(data_size)
177 key_256 = os.urandom(32)
178 key_128 = os.urandom(16)
179 key_96 = os.urandom(12)
180
181 import io
182 from ..chunkers import get_chunker # noqa
183
184 if not args.json:
185 print("Chunkers =======================================================")
186 else:
187 result["chunkers"] = []
188 size = 1000000000
189
190 def chunkit(ch):
191 with io.BytesIO(random_10M) as data_file:
192 for _ in ch.chunkify(fd=data_file):
193 pass
194
195 for spec, setup, func, vars in [
196 (
197 "buzhash,19,23,21,4095",
198 "ch = get_chunker('buzhash', 19, 23, 21, 4095, sparse=False)",
199 "chunkit(ch)",
200 locals(),
201 ),
202 # note: the buzhash64 chunker creation is rather slow, so we must keep it in setup
203 (
204 "buzhash64,19,23,21,4095",
205 "ch = get_chunker('buzhash64', 19, 23, 21, 4095, sparse=False)",
206 "chunkit(ch)",
207 locals(),
208 ),
209 ("fixed,1048576", "ch = get_chunker('fixed', 1048576, sparse=False)", "chunkit(ch)", locals()),
210 ]:
211 dt = timeit(func, setup, number=number_default, globals=vars)
212 if args.json:
213 algo, _, algo_params = spec.partition(",")
214 result["chunkers"].append({"algo": algo, "algo_params": algo_params, "size": size, "time": dt})
215 else:
216 print(f"{spec:<24} {format_file_size(size):<10} {dt:.3f}s")
217
218 from xxhash import xxh64
219 from ..checksums import crc32
220

Callers

nothing calls this directly

Calls 8

format_file_sizeFunction · 0.85
CompressionSpecClass · 0.85
json_printFunction · 0.85
digestMethod · 0.80
pbkdf2Method · 0.80
argon2Method · 0.80
as_dictMethod · 0.80
encryptMethod · 0.45

Tested by

no test coverage detected