diff --git a/benchmarks/DataManagementBench.php b/benchmarks/DataManagementBench.php new file mode 100644 index 0000000..b138966 --- /dev/null +++ b/benchmarks/DataManagementBench.php @@ -0,0 +1,57 @@ +baseDir = PathHelper::normalize(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pathwise_data_ops_bench_' . uniqid('', true)); + FlysystemHelper::createDirectory($this->baseDir); + + // Build a deterministic mixed set with duplicates. + for ($i = 0; $i < 8; $i++) { + $content = $i < 4 ? 'duplicate-content' : 'unique-content-' . $i; + FlysystemHelper::write( + PathHelper::join($this->baseDir, sprintf('artifact_%02d.txt', $i)), + $content, + ); + } + } + + public function tearDown(): void + { + if (FlysystemHelper::directoryExists($this->baseDir)) { + FlysystemHelper::deleteDirectory($this->baseDir); + } + } + + public function benchApplyRetentionScanOnly(): void + { + RetentionManager::apply($this->baseDir, null, null, 'mtime'); + } + + public function benchBuildChecksumIndex(): void + { + ChecksumIndexer::buildIndex($this->baseDir, 'sha256'); + } + + public function benchFindDuplicates(): void + { + ChecksumIndexer::findDuplicates($this->baseDir, 'sha256'); + } +} diff --git a/benchmarks/FileAndDirectoryBench.php b/benchmarks/FileAndDirectoryBench.php new file mode 100644 index 0000000..992611f --- /dev/null +++ b/benchmarks/FileAndDirectoryBench.php @@ -0,0 +1,84 @@ +baseDir = PathHelper::normalize(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pathwise_file_dir_bench_' . uniqid('', true)); + FlysystemHelper::createDirectory($this->baseDir); + + $logsDir = PathHelper::join($this->baseDir, 'logs'); + $exportsDir = PathHelper::join($this->baseDir, 'exports'); + FlysystemHelper::createDirectory($logsDir); + FlysystemHelper::createDirectory($exportsDir); + + for ($i = 0; $i < 6; $i++) { + FlysystemHelper::write( + PathHelper::join($logsDir, sprintf('entry_%02d.log', $i)), + 'benchmark-log-' . $i, + ); + } + + for ($i = 0; $i < 6; $i++) { + FlysystemHelper::write( + PathHelper::join($exportsDir, sprintf('report_%02d.txt', $i)), + str_repeat('report-line-' . $i . PHP_EOL, 10), + ); + } + + $this->filePath = PathHelper::join($this->baseDir, 'exports', 'report_00.txt'); + $this->expectedChecksum = hash('sha256', (string) FlysystemHelper::read($this->filePath)); + } + + public function tearDown(): void + { + if (FlysystemHelper::directoryExists($this->baseDir)) { + FlysystemHelper::deleteDirectory($this->baseDir); + } + } + + public function benchDirectoryFindTxtFiles(): void + { + $directory = new DirectoryOperations($this->baseDir); + $directory->find(['extension' => 'txt']); + } + + public function benchDirectoryListContentsDetailed(): void + { + $directory = new DirectoryOperations($this->baseDir); + $directory->listContents(true); + } + + public function benchDirectorySize(): void + { + $directory = new DirectoryOperations($this->baseDir); + $directory->size(); + } + + public function benchFileReadAndVerifyChecksum(): void + { + $file = new FileOperations($this->filePath); + $file->read(); + $file->verifyChecksum($this->expectedChecksum, 'sha256'); + } +} diff --git a/benchmarks/FlysystemHelperBench.php b/benchmarks/FlysystemHelperBench.php new file mode 100644 index 0000000..5ec425a --- /dev/null +++ b/benchmarks/FlysystemHelperBench.php @@ -0,0 +1,52 @@ +baseDir = PathHelper::normalize(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pathwise_bench_' . uniqid('', true)); + FlysystemHelper::createDirectory($this->baseDir); + + $this->filePath = PathHelper::join($this->baseDir, 'payload.txt'); + FlysystemHelper::write($this->filePath, str_repeat('Pathwise benchmark payload' . PHP_EOL, 128)); + } + + public function tearDown(): void + { + if (FlysystemHelper::directoryExists($this->baseDir)) { + FlysystemHelper::deleteDirectory($this->baseDir); + } + } + + public function benchChecksumSha256(): void + { + FlysystemHelper::checksum($this->filePath, 'sha256'); + } + + public function benchGetMetadataSizeAndMtime(): void + { + FlysystemHelper::size($this->filePath); + FlysystemHelper::lastModified($this->filePath); + } + + public function benchReadFileContents(): void + { + FlysystemHelper::read($this->filePath); + } +} diff --git a/benchmarks/PathHelperBench.php b/benchmarks/PathHelperBench.php new file mode 100644 index 0000000..21c8777 --- /dev/null +++ b/benchmarks/PathHelperBench.php @@ -0,0 +1,42 @@ +baseDir = PathHelper::normalize(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pathwise_stream_bench_' . uniqid('', true)); + $this->uploadDir = PathHelper::join($this->baseDir, 'uploads'); + $downloadsDir = PathHelper::join($this->baseDir, 'downloads'); + + FlysystemHelper::createDirectory($this->uploadDir); + FlysystemHelper::createDirectory($downloadsDir); + + $this->downloadFilePath = PathHelper::join($downloadsDir, 'dataset.txt'); + FlysystemHelper::write($this->downloadFilePath, str_repeat('download-content' . PHP_EOL, 64)); + + $this->uploadProcessor = new UploadProcessor(); + $this->uploadProcessor->setDirectorySettings($this->uploadDir, false); + $this->uploadProcessor->setValidationSettings([], 2 * 1024 * 1024); + + $this->downloadProcessor = new DownloadProcessor(); + $this->downloadProcessor->setAllowedRoots([$this->baseDir]); + } + + public function tearDown(): void + { + if (FlysystemHelper::directoryExists($this->baseDir)) { + FlysystemHelper::deleteDirectory($this->baseDir); + } + } + + public function benchPrepareDownloadMetadata(): void + { + $this->downloadProcessor->prepareDownload($this->downloadFilePath, 'dataset.txt', null); + } + + public function benchProcessUpload(): void + { + $tmpUpload = tempnam(sys_get_temp_dir(), 'pathwise_upload_bench_'); + if (!is_string($tmpUpload)) { + return; + } + + file_put_contents($tmpUpload, str_repeat('upload-payload', 128)); + + try { + $destination = $this->uploadProcessor->processUpload([ + 'error' => UPLOAD_ERR_OK, + 'size' => filesize($tmpUpload) ?: 0, + 'tmp_name' => $tmpUpload, + 'name' => 'payload.txt', + ]); + FlysystemHelper::delete($destination); + } finally { + if (is_file($tmpUpload)) { + unlink($tmpUpload); + } + } + } + + public function benchStreamDownload(): void + { + $output = fopen('php://temp', 'w+b'); + if (!is_resource($output)) { + return; + } + + try { + $this->downloadProcessor->streamDownload($this->downloadFilePath, $output); + } finally { + fclose($output); + } + } +}