



"""simple docstring"""
import math
from timeit import timeit



def 				lowerCAmelCase_(      lowercase_   :							Any							)		->				int:
				_lowerCamelCase					     = 0
				_lowerCamelCase					     = abs(lowercase_							)
				while True:
								_lowerCamelCase					     = n // 10
								digits += 1
								if n == 0:
												break
				return digits



def 				lowerCAmelCase_(      lowercase_   :							List[Any]							)		->				int:
				return 1 if n == 0 else math.floor(math.log(abs(lowercase_							)  ,      10							) + 1							)



def 				lowerCAmelCase_(      lowercase_   :							str							)		->				int:
				return len(str(abs(lowercase_							)							)							)



def 				lowerCAmelCase_(      )		->				None:
				from collections.abc import Callable

				def benchmark_a_function(lowercase_   :							Dict  ,      lowercase_   :							List[Any]							) -> None:
								_lowerCamelCase					     = F"""{func.__name__}({value})"""
								_lowerCamelCase					     = timeit(F"""__main__.{call}"""  ,      setup='''import __main__'''							)
								print(F"""{call}: {func(lowercase_							)} -- {timing} seconds"""							)

				for value in (26_21_44, 11_25_89_99_06_84_26_24, 1_26_76_50_60_02_28_22_94_01_49_67_03_20_53_76):
								for func in (num_digits, num_digits_fast, num_digits_faster):
												benchmark_a_function(lowercase_  ,      lowercase_							)
								print()


if __name__ == "__main__":
			import doctest

			doctest.testmod()
			benchmark()







'''simple docstring'''







import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp





def    _lowerCAmelCase						(						)					->					List[str]:
			__lowerCAmelCase											=				ArgumentParser(
			    description=(
			        """PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes"""
			    )	)

			# Optional arguments for the launch helper
			parser.add_argument("""--num_cores"""					,	type=lowercase					,	default=1					,	help="""Number of TPU cores to use (1 or 8)."""	)

			# positional
			parser.add_argument(
			    """training_script"""					,	type=lowercase					,	help=(
			        """The full path to the single TPU training """
			        """program/script to be launched in parallel, """
			        """followed by all the arguments for the """
			        """training script"""
			    )					,	)

			# rest from the training program
			parser.add_argument("""training_script_args"""					,	nargs=lowercase	)

			return parser.parse_args()





def    _lowerCAmelCase						(						)					->					Any:
			__lowerCAmelCase											=				parse_args()

			# Import training_script as a module.
			__lowerCAmelCase											=				Path(args.training_script	)
			sys.path.append(str(script_fpath.parent.resolve()	)	)
			__lowerCAmelCase											=				script_fpath.stem
			__lowerCAmelCase											=				importlib.import_module(lowercase	)

			# Patch sys.argv
			__lowerCAmelCase											=				[args.training_script] + args.training_script_args + ["""--tpu_num_cores""", str(args.num_cores	)]

			xmp.spawn(mod._mp_fn					,	args=()					,	nprocs=args.num_cores	)


if __name__ == "__main__":
	main()

