Skip to content

Commit

Permalink
working but not faster
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdenobel committed Nov 7, 2023
1 parent c359aa5 commit 4002014
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
32 changes: 15 additions & 17 deletions include/ioh/common/file.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#pragma once

#include <string>
#include <utility>
#include "ioh/common/format.hpp"
Expand Down Expand Up @@ -422,10 +421,9 @@ namespace ioh::common::file
void open(const fs::path &new_path)
{
close();

path = new_path;
const auto error = fopen_s(&file_ptr, path.generic_string().c_str(), "ab");
if (error != 0)
file_ptr = fopen(path.generic_string().c_str(), "ab");
if (file_ptr == NULL)
{
std::cerr << "creating cachedfile: " << get_error() << std::endl;
}
Expand All @@ -435,11 +433,7 @@ namespace ioh::common::file
{
if (is_open())
{
const auto ret = fwrite(buffer.data(), sizeof(char), buffer.size(), file_ptr);
if (ret != buffer.size())
{
std::cerr << "destroying cachedfile: " << get_error() << std::endl;
}
write_chunk(buffer.size());
fclose(file_ptr);
file_ptr = nullptr;
buffer.clear();
Expand All @@ -454,18 +448,22 @@ namespace ioh::common::file
close();
}

void write(const char *data, const size_t size)
void write_chunk(const size_t chunk_size) {
const auto ret = fwrite(buffer.data(), sizeof(char), chunk_size, file_ptr);
if (ret != chunk_size)
{
std::cerr << "writing cached file: " << get_error() << std::endl;
}
buffer.erase(buffer.begin(), buffer.begin() + chunk_size);
}

void write(const char *data, const size_t data_size)
{
buffer.insert(buffer.end(), data, data + size);
buffer.insert(buffer.end(), data, data + data_size);
if (buffer.size() >= PAGE_SIZE)
{
const size_t size = (buffer.size() / PAGE_SIZE) * PAGE_SIZE;
const auto ret = fwrite(buffer.data(), sizeof(char), size, file_ptr);
if (ret != buffer.size())
{
std::cerr << "writing cached file: " << get_error() << std::endl;
}
buffer.erase(buffer.begin(), buffer.begin() + size);
write_chunk(size);
}
}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def build_extension(self, ext):
description="The experimenter for Iterative Optimization Heuristics",
long_description=long_description,
long_description_content_type="text/markdown",
packages=find_packages(),
packages=["ioh"],
package_dir={"IOHexperimenter": "ioh"},
include_package_data=True,
exclude_package_data={"": ["src/*", "*CMakeLists.txt", "*README.md"]},
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp/logger/test_flatfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST_F(BaseTest, logger_flatfile)
auto logger = logger::FlatFile( {always}, {transformed_y}, "IOH.dat", "." );

const int runs = 3;
const int samples = 3;
const int samples = 300;

for(auto pb : std::array<problem::BBOB*,3>({&p0,&p1,&p2})) {
pb->attach_logger(logger);
Expand Down

0 comments on commit 4002014

Please sign in to comment.