


import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


__lowerCamelCase   	=  100000000000
__lowerCamelCase   	=  10000

__lowerCamelCase	,							__lowerCamelCase   	=  os.path.split(__file__)
__lowerCamelCase   	=  os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))



def 			_a      (    __UpperCamelCase	,	__UpperCamelCase			):
     a_     :  Dict				      =     pa.Table.from_pydict({"""col""": [0] * chunk_size}			)
     a_     :  Tuple				      =     pa.concat_tables([table] * (num_examples // chunk_size)			)
     return datasets.Dataset(__UpperCamelCase	,	fingerprint="""table_100B"""			)


@dataclass
class 	a__						:
       lowerCamelCase__:  int
       lowerCamelCase__:  int
       lowerCamelCase__:  int
       lowerCamelCase__:  int

       def     UpperCAmelCase( self   :  List[Any]     ):
            a_     :  Any				      =     np.random.default_rng(self.seed     )
            a_     :  List[str]				      =     rng.integers(low=self.low   ,				high=self.high   ,				size=self.size     ).tolist()

       def __iter__( self   :  Union[str, Any]     ):
            return iter(self._sampled_values     )

       def __len__( self   :  Optional[Any]     ):
            return self.size



@get_duration
def 			_a      (    __UpperCamelCase			):
     a_     :  int				      =     dataset[0]



@get_duration
def 			_a      (    __UpperCamelCase			):
     a_     :  Optional[int]				      =     dataset[-1]



@get_duration
def 			_a      (    __UpperCamelCase			):
     a_     :  Optional[Any]				      =     dataset[range(len(__UpperCamelCase			) // 2	,	len(__UpperCamelCase			) // 2 + 1_0_2_4			)]



@get_duration
def 			_a      (    __UpperCamelCase			):
     a_     :  Tuple				      =     dataset[RandIter(0	,	len(__UpperCamelCase			)	,	1_0_2_4	,	seed=4_2			)]



def 			_a      (    ):
     a_     :  Optional[Any]				      =     {"""num examples""": SPEED_TEST_N_EXAMPLES}
     a_     :  int				      =     (get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
     print("""generating dataset"""			)
     a_     :  List[str]				      =     generate_100B_dataset(num_examples=__UpperCamelCase	,	chunk_size=__UpperCamelCase			)
     print("""Functions"""			)
     for func in functions:
          print(func.__name__			)
          a_     :  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_table_100B()











import math
from timeit import timeit

def 			__lowerCamelCase     (						snake_case__						)				->    int:






						"""simple docstring"""





						_SCREAMING_SNAKE_CASE       =    0
						_SCREAMING_SNAKE_CASE       =    abs(snake_case__						)
						while True:
												_SCREAMING_SNAKE_CASE       =    n // 10
												digits += 1
												if n == 0:
																		break
						return digits

def 			__lowerCamelCase     (						snake_case__						)				->    int:






						"""simple docstring"""





						return 1 if n == 0 else math.floor(math.log(abs(snake_case__						)			,10						) + 1						)

def 			__lowerCamelCase     (						snake_case__						)				->    int:






						"""simple docstring"""





						return len(str(abs(snake_case__						)						)						)

def 			__lowerCamelCase     (						)				->    None:






						"""simple docstring"""





						from collections.abc import Callable

						def benchmark_a_function(snake_case__			,snake_case__						) -> None:
												_SCREAMING_SNAKE_CASE       =    F'{func.__name__}({value})'
												_SCREAMING_SNAKE_CASE       =    timeit(F'__main__.{call}'			,setup="""import __main__"""						)
												print(F'{call}: {func(snake_case__						)} -- {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(snake_case__			,snake_case__						)
												print()


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()

