


import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


lowerCAmelCase__						=			10_00_00_00_00_00
lowerCAmelCase__						=			1_00_00

lowerCAmelCase__		,lowerCAmelCase__						=			os.path.split(__file__)
lowerCAmelCase__						=			os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))
def 							_UpperCAmelCase    (UpperCamelCase__					:  int    ,							UpperCamelCase__					:  int						):
       _A				:	str       =			pa.Table.from_pydict({"col": [0] * chunk_size}						)
       _A				:	Dict       =			pa.concat_tables([table] * (num_examples // chunk_size)						)
       return datasets.Dataset(UpperCamelCase__    ,							fingerprint="table_100B"						)







@dataclass
class 					lowerCAmelCase__	:




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE        =			42
     __SCREAMING_SNAKE_CASE        =			42
     __SCREAMING_SNAKE_CASE        =			42
     __SCREAMING_SNAKE_CASE        =			42


     def 			_lowerCamelCase			(						self)      ->    Dict:
            _A				:	Any       =			np.random.default_rng(self.seed)
            _A				:	List[Any]       =			rng.integers(low=self.low			,						high=self.high			,						size=self.size).tolist()


     def __iter__(						self)      ->    str:
            return iter(self._sampled_values)


     def __len__(						self)      ->    List[Any]:
            return self.size




@get_duration
def 							_UpperCAmelCase    (UpperCamelCase__					:  datasets.Dataset						):
       _A				:	int       =			dataset[0]
@get_duration
def 							_UpperCAmelCase    (UpperCamelCase__					:  datasets.Dataset						):
       _A				:	int       =			dataset[-1]
@get_duration
def 							_UpperCAmelCase    (UpperCamelCase__					:  datasets.Dataset						):
       _A				:	Optional[int]       =			dataset[range(len(UpperCamelCase__						) // 2    ,							len(UpperCamelCase__						) // 2 + 1024						)]
@get_duration
def 							_UpperCAmelCase    (UpperCamelCase__					:  datasets.Dataset						):
       _A				:	str       =			dataset[RandIter(0    ,							len(UpperCamelCase__						)    ,							1024    ,							seed=42						)]
def 							_UpperCAmelCase    ():
       _A				:	Dict       =			{"num examples": SPEED_TEST_N_EXAMPLES}
       _A				:	Union[str, Any]       =			(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
       print("generating dataset"						)
       _A				:	Optional[Any]       =			generate_100B_dataset(num_examples=UpperCamelCase__    ,							chunk_size=UpperCamelCase__						)
       print("Functions"						)
       for func in functions:
              print(func.__name__						)
              _A				:	Union[str, 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()




from __future__ import annotations

from typing import Any







class 					lowerCAmelCase__	:




     '''simple docstring'''


     def __init__(						self			,						__lowerCamelCase			,						__lowerCamelCase)      ->    None:  # noqa: A002
            _A				:	List[str]       =			item
            _A				:	List[Any]       =			next







class 					lowerCAmelCase__	:




     '''simple docstring'''


     def __init__(						self)      ->    None:
            _A				:	Node | None       =			None
            _A				:	List[Any]       =			0


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase)      ->    None:
            _A				:	Union[str, Any]       =			Node(__lowerCamelCase			,						self.head)
            self.size += 1


     def 			_lowerCamelCase			(						self)      ->    Any:
            # Switched 'self.is_empty()' to 'self.head is None'
            # because mypy was considering the possibility that 'self.head'
            # can be None in below else part and giving error
            if self.head is None:
                   return None
            else:
                   _A				:	str       =			self.head.item
                   _A				:	List[Any]       =			self.head.next
                   self.size -= 1
                   return item


     def 			_lowerCamelCase			(						self)      ->    bool:
            return self.head is None


     def __str__(						self)      ->    str:
            if self.is_empty():
                   return ""
            else:
                   _A				:	List[str]       =			self.head
                   _A				:	Optional[int]       =			""
                   _A				:	list[str]       =			[]
                   while iterate:
                          item_list.append(str(iterate.item))
                          _A				:	Optional[Any]       =			iterate.next

                   _A				:	List[str]       =			" --> ".join(__lowerCamelCase)

                   return item_str


     def __len__(						self)      ->    int:
            return self.size
