

import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


lowerCAmelCase__             =		1_0_0_0_0_0_0_0_0_0_0_0
lowerCAmelCase__             =		1_0_0_0_0

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






def        lowerCamelCase_  (				UpperCAmelCase_				:  int				,							UpperCAmelCase_				:  int						)    ->					datasets.Dataset:




	'''simple docstring'''




	_UpperCamelCase :		Dict								=    pa.Table.from_pydict({'col': [0] * chunk_size}						)
	_UpperCamelCase :		Dict								=    pa.concat_tables([table] * (num_examples // chunk_size)						)
	return datasets.Dataset(UpperCAmelCase_				,							fingerprint='table_100B'						)







@dataclass
class 						lowercase     :


		"""simple docstring"""




		a__       							=	42
		a__       							=	42
		a__       							=	42
		a__       							=	42


		def 		A__       (					self):
			_UpperCamelCase :		Dict								=    np.random.default_rng(self.seed)
			_UpperCamelCase :		Tuple								=    rng.integers(low=self.low						,							high=self.high						,							size=self.size).tolist()


		def __iter__(					self):
			return iter(self._sampled_values)






		def __len__(					self):
			return self.size






@get_duration
def        lowerCamelCase_  (				UpperCAmelCase_				:  datasets.Dataset						)    ->					Dict:




	'''simple docstring'''




	_UpperCamelCase :		Tuple								=    dataset[0]






@get_duration
def        lowerCamelCase_  (				UpperCAmelCase_				:  datasets.Dataset						)    ->					List[Any]:




	'''simple docstring'''




	_UpperCamelCase :		int								=    dataset[-1]






@get_duration
def        lowerCamelCase_  (				UpperCAmelCase_				:  datasets.Dataset						)    ->					List[str]:




	'''simple docstring'''




	_UpperCamelCase :		Tuple								=    dataset[range(len(UpperCAmelCase_						) // 2				,							len(UpperCAmelCase_						) // 2 + 1_0_2_4						)]






@get_duration
def        lowerCamelCase_  (				UpperCAmelCase_				:  datasets.Dataset						)    ->					Optional[int]:




	'''simple docstring'''




	_UpperCamelCase :		Optional[Any]								=    dataset[RandIter(0				,							len(UpperCAmelCase_						)				,							1_0_2_4				,							seed=4_2						)]






def        lowerCamelCase_  (				)    ->					List[str]:




	'''simple docstring'''




	_UpperCamelCase :		Tuple								=    {'num examples': SPEED_TEST_N_EXAMPLES}
	_UpperCamelCase :		Union[str, Any]								=    (get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
	print('generating dataset'						)
	_UpperCamelCase :		Dict								=    generate_100B_dataset(num_examples=UpperCAmelCase_				,							chunk_size=UpperCAmelCase_						)
	print('Functions'						)
	for func in functions:
		print(func.__name__						)
		_UpperCamelCase :		Optional[int]								=    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 posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry







class 						lowercase     (					_lowercase				):


		"""simple docstring"""




		a__       							=	"mock"


		def __init__(					self						,							*__snake_case						,							__snake_case						,							**__snake_case):
			super().__init__()
			_UpperCamelCase :		str								=    LocalFileSystem(*__snake_case						,							**__snake_case)
			_UpperCamelCase :		str								=    Path(__snake_case).resolve().as_posix() + '/'


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		int								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.mkdir(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		List[str]								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.makedirs(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.rmdir(__snake_case)


		def 		A__       (					self						,							__snake_case						,							__snake_case=True						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		Union[str, Any]								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			_UpperCamelCase :		Tuple								=    self._fs.ls(__snake_case						,							detail=__snake_case						,							*__snake_case						,							**__snake_case)
			if detail:
				return [{**info, "name": info["name"][len(self.local_root_dir) :]} for info in out]
			else:
				return [name[len(self.local_root_dir) :] for name in out]


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		Optional[Any]								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			_UpperCamelCase :		Optional[Any]								=    dict(self._fs.info(__snake_case						,							*__snake_case						,							**__snake_case))
			_UpperCamelCase :		Dict								=    out['name'][len(self.local_root_dir) :]
			return out


		def 		A__       (					self						,							__snake_case						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		str								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			_UpperCamelCase :		Tuple								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.cp_file(__snake_case						,							__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.rm_file(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		int								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.rm(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs._open(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.created(__snake_case)


		def 		A__       (					self						,							__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.modified(__snake_case)






		@classmethod
		def 		A__       (					cls						,							__snake_case):
			_UpperCamelCase :		List[Any]								=    stringify_path(__snake_case)
			if path.startswith('mock://'):
				_UpperCamelCase :		int								=    path[7:]
			return path







class 						lowercase     (					_lowercase				):


		"""simple docstring"""




		a__       							=	"tmp"
		a__       							=	None


		def __init__(					self						,							*__snake_case						,							**__snake_case):
			assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
			super().__init__(*__snake_case						,							**__snake_case						,							local_root_dir=self.tmp_dir						,							auto_mkdir=__snake_case)






		@classmethod
		def 		A__       (					cls						,							__snake_case):
			_UpperCamelCase :		Optional[int]								=    stringify_path(__snake_case)
			if path.startswith('tmp://'):
				_UpperCamelCase :		Optional[Any]								=    path[6:]
			return path






@pytest.fixture
def        lowerCamelCase_  (				)    ->					Dict:




	'''simple docstring'''




	_UpperCamelCase :		List[str]								=    MockFileSystem
	_UpperCamelCase :		Optional[int]								=    TmpDirFileSystem
	yield
	del _fsspec_registry["mock"]
	del _fsspec_registry["tmp"]






@pytest.fixture
def        lowerCamelCase_  (				UpperCAmelCase_				:  Any				,							UpperCAmelCase_				:  Optional[int]						)    ->					Optional[int]:




	'''simple docstring'''




	_UpperCamelCase :		str								=    tmp_path_factory.mktemp('mockfs'						)
	return MockFileSystem(local_root_dir=UpperCAmelCase_				,							auto_mkdir=UpperCAmelCase_						)







@pytest.fixture
def        lowerCamelCase_  (				UpperCAmelCase_				:  Tuple				,							UpperCAmelCase_				:  Union[str, Any]						)    ->					int:




	'''simple docstring'''




	_UpperCamelCase :		Dict								=    tmp_path_factory.mktemp('tmpfs'						)
	with patch.object(UpperCAmelCase_				,							'tmp_dir'				,							UpperCAmelCase_						):
		yield TmpDirFileSystem()




