Skip to content

Commit

Permalink
Add single threaded benchmark_disk_read script
Browse files Browse the repository at this point in the history
  • Loading branch information
suri-kumkaran committed Dec 11, 2024
1 parent 1513ffd commit 36c9fcc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ target_link_libraries(test_streaming_scenario ${PROJECT_NAME} ${DISKANN_TOOLS_TC
add_executable(test_insert_deletes_consolidate test_insert_deletes_consolidate.cpp)
target_link_libraries(test_insert_deletes_consolidate ${PROJECT_NAME} ${DISKANN_TOOLS_TCMALLOC_LINK_OPTIONS} Boost::program_options)

add_executable(benchmark_reads benchmark_reads.cpp)
target_link_libraries(benchmark_reads ${PROJECT_NAME} ${DISKANN_TOOLS_TCMALLOC_LINK_OPTIONS} Boost::program_options)

if (NOT MSVC)
install(TARGETS build_memory_index
build_stitched_index
Expand All @@ -37,6 +40,7 @@ if (NOT MSVC)
range_search_disk_index
test_streaming_scenario
test_insert_deletes_consolidate
benchmark_reads
RUNTIME
)
endif()
53 changes: 53 additions & 0 deletions apps/benchmark_reads.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <iostream>
#include <cstdlib>
#include "windows_aligned_file_reader.h"
#include "aligned_file_reader.h"
#include "utils.h"

using namespace std;
using namespace diskann;

#define IS_ALIGNED(X, Y) ((uint64_t)(X) % (uint64_t)(Y) == 0)

#define SECTOR_LEN 4096

void do_reads()
{
string file_name = "C:\\DiskANN\\Data\\turning_100k\\index_disk.index";
auto reader = new WindowsAlignedFileReader();
reader->open(file_name.c_str());
auto ctx = reader->get_ctx();

std::vector<AlignedRead> read_reqs;
int num_sectors = 100;

char *buf = nullptr;
alloc_aligned((void **)&buf, num_sectors * SECTOR_LEN, SECTOR_LEN);

// create read requests
for (size_t i = 0; i < num_sectors; ++i)
{
AlignedRead read;
read.len = SECTOR_LEN;
read.buf = buf + i * SECTOR_LEN;
auto sector_id = (rand() % 10000);
read.offset = sector_id * SECTOR_LEN;
if (read.offset)
read_reqs.push_back(read);
}

auto s = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 10000; i++)
{
reader->read(read_reqs, ctx, false);
}
auto e = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = e - s;
cout << "Time taken to read: " << diff.count() << endl;
}

int main()
{
cout << "Hello World" << endl;
do_reads();
}

0 comments on commit 36c9fcc

Please sign in to comment.