@@ -62,6 +62,8 @@ def bench_bytes_hex_sep():
6262 """Benchmark bytes.hex() with separator."""
6363 print ("\n bytes.hex(':') with separator (every byte):" )
6464 for size in SIZES :
65+ if size > 256 :
66+ continue
6567 data = DATA [size ]
6668 ns = run_benchmark (lambda d = data : d .hex (':' ))
6769 print (f" { ns :7.1f} ns { format_size (size )} " )
@@ -72,13 +74,26 @@ def bench_bytes_hex_sep_group():
7274 print ("\n bytes.hex(':', 2) with separator (every 2 bytes):" )
7375 # Skip 0 and 1 byte sizes since grouping doesn't apply well
7476 for size in SIZES :
75- if size < 2 :
77+ if size < 2 or size > 256 :
7678 continue
7779 data = DATA [size ]
7880 ns = run_benchmark (lambda d = data : d .hex (':' , 2 ))
7981 print (f" { ns :7.1f} ns { format_size (size )} " )
8082
8183
84+ def bench_bytes_hex_sep_4_thru_20 ():
85+ """Benchmark bytes.hex() with separators in the 4-20 bytes range."""
86+ for sep_width in (4 , 8 , 16 , 20 ):
87+ print (f"\n bytes.hex('\\ n', { sep_width } ) with - (every { sep_width } bytes):" )
88+ # Only test sizes > width where this grouping is meaningful
89+ for size in SIZES :
90+ if size <= sep_width :
91+ continue
92+ data = DATA [size ]
93+ ns = run_benchmark (lambda d = data : d .hex ('-' , sep_width ))
94+ print (f" { ns :7.1f} ns { format_size (size )} " )
95+
96+
8297def bench_bytes_hex_newline_32 ():
8398 """Benchmark bytes.hex() with newline separator every 32 bytes.
8499
@@ -125,6 +140,8 @@ def bench_binascii_hexlify_sep():
125140 """Benchmark binascii.hexlify() with separator."""
126141 print ("\n binascii.hexlify(sep=':') with separator:" )
127142 for size in SIZES :
143+ if size > 256 :
144+ continue
128145 data = DATA [size ]
129146 ns = run_benchmark (lambda d = data : binascii .hexlify (d , ':' ))
130147 print (f" { ns :7.1f} ns { format_size (size )} " )
@@ -194,6 +211,7 @@ def bench_hash_hexdigest_only():
194211 bench_bytes_hex ()
195212 bench_bytes_hex_sep ()
196213 bench_bytes_hex_sep_group ()
214+ bench_bytes_hex_sep_4_thru_20 ()
197215 bench_bytes_hex_newline_32 ()
198216 bench_bytearray_hex ()
199217 bench_memoryview_hex ()
0 commit comments