diff options
author | Andrew Kaster <akaster@serenityos.org> | 2021-06-30 21:58:18 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-06 17:22:45 +0200 |
commit | f0d562131ffcb2d84f9f0cc32b86ab244b82d1e5 (patch) | |
tree | 95dbd931a367a32637c43eb439639ca4bad78d02 /Userland/Applications/Spreadsheet | |
parent | b7ae5619451ff5c796108bc87f46138c3a8ca923 (diff) | |
download | serenity-f0d562131ffcb2d84f9f0cc32b86ab244b82d1e5.zip |
Tests: Generate data in memory for TestXSV benchmark case
The actual data file for this benchmark was never actually committed to
the repository, so let's generate 100k identical lines in memory to be
the fairly large data for this test instead.
Diffstat (limited to 'Userland/Applications/Spreadsheet')
-rw-r--r-- | Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp b/Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp index 0569b59dd4..a24306a31b 100644 --- a/Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp +++ b/Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp @@ -8,6 +8,7 @@ #include "../CSV.h" #include "../XSV.h" +#include <AK/ByteBuffer.h> #include <LibCore/File.h> TEST_CASE(should_parse_valid_data) @@ -82,13 +83,18 @@ TEST_CASE(should_iterate_rows) BENCHMARK_CASE(fairly_big_data) { - auto file_or_error = Core::File::open(__FILE__ ".data", Core::OpenMode::ReadOnly); - EXPECT_EQ_FORCE(file_or_error.is_error(), false); + constexpr auto num_rows = 100000u; + constexpr auto line = "well,hello,friends,1,2,3,4,5,6,7,8,pizza,guacamole\n"sv; + auto buf = ByteBuffer::create_uninitialized((line.length() * num_rows) + 1); + buf[buf.size() - 1] = '\0'; - auto data = file_or_error.value()->read_all(); - auto csv = Reader::CSV { data, Reader::default_behaviours() | Reader::ParserBehaviour::ReadHeaders }; + for (size_t row = 0; row <= num_rows; ++row) { + memcpy(buf.offset_pointer(row * line.length()), line.characters_without_null_termination(), line.length()); + } + + auto csv = Reader::CSV { (char const*)buf.data(), Reader::default_behaviours() | Reader::ParserBehaviour::ReadHeaders }; csv.parse(); EXPECT(!csv.has_error()); - EXPECT_EQ(csv.size(), 100000u); + EXPECT_EQ(csv.size(), num_rows); } |