ManManson commented on code in PR #13796: URL: https://github.com/apache/arrow/pull/13796#discussion_r948181347
########## cpp/src/arrow/filesystem/localfs_benchmark.cc: ########## @@ -0,0 +1,147 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <memory> + +#include "benchmark/benchmark.h" + +#include <arrow/status.h> +#include <arrow/testing/random.h> +#include <arrow/util/async_generator.h> +#include <arrow/util/string_view.h> +#include "arrow/filesystem/localfs.h" +#include "arrow/io/file.h" +#include "arrow/table.h" +#include "arrow/testing/future_util.h" +#include "arrow/testing/gtest_util.h" +#include "arrow/testing/random.h" +#include "arrow/util/formatting.h" +#include "arrow/util/io_util.h" +#include "arrow/util/make_unique.h" +#include "arrow/util/string_view.h" + +namespace arrow { + +namespace fs { + +using arrow::internal::make_unique; +using arrow::internal::TemporaryDir; + +/// Set up hierarchical directory structure to test asynchronous +/// file discovery interface (GetFileInfoGenerator()) in the LocalFileSystem +/// class. +/// +/// The main routine of the class is `InitializeDatasetStructure()`, which +/// does the following: +/// 1. Create `num_files_` empty files under specified root directory. +/// 2. Create `num_dirs_` additional sub-directories in the current dir. +/// 3. Check if the specified recursion limit is reached (controlled by `nesting_depth_`). +/// a. Return if recursion limit reached. +/// b. Recurse into each sub-directory and perform steps above, increasing current +/// nesting level. +class LocalFSFixture : public benchmark::Fixture { + public: + void SetUp(const benchmark::State& state) override { + ASSERT_OK_AND_ASSIGN(tmp_dir_, TemporaryDir::Make("localfs-test-")); + + auto options = LocalFileSystemOptions::Defaults(); + fs_ = make_unique<LocalFileSystem>(options); + + InitializeDatasetStructure(0, tmp_dir_->path()); + } + + void InitializeDatasetStructure(size_t cur_nesting_level, + arrow::internal::PlatformFilename cur_root_dir) { + ASSERT_OK(arrow::internal::CreateDir(cur_root_dir)); + + arrow::internal::StringFormatter<Int32Type> format; + for (size_t i = 0; i < num_files_; ++i) { + std::string fname = "file_"; + format(i, [&fname](util::string_view formatted) { + fname.append(formatted.data(), formatted.size()); + }); + ASSERT_OK_AND_ASSIGN(auto path, cur_root_dir.Join(std::move(fname))); + ASSERT_OK(MakeEmptyFile(path.ToString())); + } + + if (cur_nesting_level == nesting_depth_) { + return; + } + + for (size_t i = 0; i < num_dirs_; ++i) { + std::string dirname = "dir_"; + format(i, [&dirname](util::string_view formatted) { + dirname.append(formatted.data(), formatted.size()); + }); + ASSERT_OK_AND_ASSIGN(auto path, cur_root_dir.Join(std::move(dirname))); + InitializeDatasetStructure(cur_nesting_level + 1, std::move(path)); + } + } + + Status MakeEmptyFile(const std::string& path) { + return io::FileOutputStream::Open(path).status(); + } + + protected: + std::unique_ptr<TemporaryDir> tmp_dir_; + std::unique_ptr<LocalFileSystem> fs_; + + const size_t nesting_depth_ = 2; + const size_t num_dirs_ = 10; + const size_t num_files_ = 10000; Review Comment: I agree, win and macOS users will almost surely suffer in this case... So, to keep benchmarking fast, let `num_files_` be 1k, then. :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
