MCPcopy Index your code
hub / github.com/python/cpython / main

Function main

Tools/picklebench/memory_dos_impact.py:947–1065  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

945
946
947def main():
948 parser = argparse.ArgumentParser(
949 description="Benchmark pickle unpickling performance for large objects"
950 )
951 parser.add_argument(
952 '--sizes',
953 type=int,
954 nargs='+',
955 default=None,
956 metavar='MiB',
957 help=f'Object sizes to test in MiB (default: {DEFAULT_SIZES_MIB})'
958 )
959 parser.add_argument(
960 '--protocol',
961 type=int,
962 default=5,
963 choices=[0, 1, 2, 3, 4, 5],
964 help='Pickle protocol version (default: 5)'
965 )
966 parser.add_argument(
967 '--iterations',
968 type=int,
969 default=3,
970 help='Number of benchmark iterations (default: 3)'
971 )
972 parser.add_argument(
973 '--format',
974 choices=['text', 'markdown', 'json'],
975 default='text',
976 help='Output format (default: text)'
977 )
978 parser.add_argument(
979 '--baseline',
980 type=str,
981 metavar='PYTHON',
982 help='Path to baseline Python interpreter for comparison (e.g., ../main-build/python)'
983 )
984 parser.add_argument(
985 '--antagonistic',
986 action='store_true',
987 help='Run antagonistic/malicious pickle tests (DoS protection benchmark)'
988 )
989
990 args = parser.parse_args()
991
992 # Handle antagonistic mode
993 if args.antagonistic:
994 # Antagonistic mode uses claimed sizes in MB, not actual data sizes
995 if args.sizes is None:
996 claimed_sizes_mb = AntagonisticTestSuite.DEFAULT_ANTAGONISTIC_SIZES_MB
997 else:
998 claimed_sizes_mb = args.sizes
999
1000 print(f"Running ANTAGONISTIC pickle benchmark (DoS protection test)...")
1001 print(f"Claimed sizes: {claimed_sizes_mb} MiB (actual data: 1KB each)")
1002 print(f"NOTE: These pickles will FAIL to unpickle (expected)")
1003 print()
1004

Callers 1

Calls 11

parse_argsMethod · 0.95
run_all_testsMethod · 0.95
existsMethod · 0.95
PathClass · 0.90
_format_outputFunction · 0.85
format_comparisonMethod · 0.80
TestSuiteClass · 0.70
add_argumentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…