




'''simple docstring'''





import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


a		:	List[Any]       =      5_0_0_0_0_0

a      ,				a		:	Optional[int]       =      os.path.split(__file__)
a		:	int       =      os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_						):
    _a				:							int							       =      dataset.select(range(0   ,	len(UpperCAmelCase_						)   ,	2						)						)





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_						):
    _a				:							int							       =      dataset.sort("""numbers"""						)





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_						):
    _a				:							List[str]							       =      dataset.shuffle()





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_						):
    _a				:							Optional[int]							       =      dataset.train_test_split(0.1						)





@get_duration
def UpperCAmelCase    (       UpperCAmelCase_   ,	UpperCAmelCase_=10						):
    for shard_id in range(UpperCAmelCase_						):
        _a				:							Optional[int]							       =      dataset.shard(UpperCAmelCase_   ,	UpperCAmelCase_						)





def UpperCAmelCase    (       ):
    _a				:							int							       =      {"""num examples""": SPEED_TEST_N_EXAMPLES}
    _a				:							int							       =      (select, sort, shuffle, train_test_split, shard)
    with tempfile.TemporaryDirectory() as tmp_dir:
        print("""generating dataset"""						)
        _a				:							Tuple							       =      datasets.Features({"""text""": datasets.Value("""string"""						), """numbers""": datasets.Value("""float32"""						)}						)
        _a				:							Optional[int]							       =      generate_example_dataset(
            os.path.join(UpperCAmelCase_   ,	"""dataset.arrow"""						)   ,	UpperCAmelCase_   ,	num_examples=UpperCAmelCase_						)
        print("""Functions"""						)
        for func in functions:
            print(func.__name__						)
            _a				:							Optional[Any]							       =      func(UpperCAmelCase_						)

    with open(UpperCAmelCase_   ,	"""wb"""						) as f:
        f.write(json.dumps(UpperCAmelCase_						).encode("""utf-8"""						)						)


if __name__ == "__main__":  # useful to run the profiler
  benchmark_indices_mapping()




"""simple docstring"""





import math
from timeit import timeit







def       __a	(						__lowerCamelCase    ):
   UpperCAmelCase_   :   Tuple     	=       0
   UpperCAmelCase_   :   Any     	=       abs(__lowerCamelCase    )
   while True:
      UpperCAmelCase_   :   Optional[int]     	=       n // 10
      digits += 1
      if n == 0:
         break
   return digits







def       __a	(						__lowerCamelCase    ):
   return 1 if n == 0 else math.floor(math.log(abs(__lowerCamelCase    ),						10    ) + 1    )







def       __a	(						__lowerCamelCase    ):
   return len(str(abs(__lowerCamelCase    )    )    )







def       __a	(						):
   from collections.abc import Callable

   def benchmark_a_function(__lowerCamelCase,						__lowerCamelCase    ) -> None:
      UpperCAmelCase_   :   Optional[Any]     	=       f"""{func.__name__}({value})"""
      UpperCAmelCase_   :   Optional[int]     	=       timeit(f"""__main__.{call}""",						setup="import __main__"    )
      print(f"""{call}: {func(__lowerCamelCase    )} -- {timing} seconds"""    )

   for value in (26_2144, 1125_8999_0684_2624, 126_7650_6002_2822_9401_4967_0320_5376):
      for func in (num_digits, num_digits_fast, num_digits_faster):
         benchmark_a_function(__lowerCamelCase,						__lowerCamelCase    )
      print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()


