Sparse Virtual File System  0.4.1
A Sparse Virtual File System.
test_svfs.cpp
Go to the documentation of this file.
1 
32 //#include <iostream>
33 //#include <iomanip>
34 #include <sstream>
35 //#include <thread>
36 
37 #include "svfs.h"
38 #include "test_svfs.h"
39 
40 
41 namespace SVFS {
42  namespace Test {
43 
44  // Simulate writing a low level RP66V1 index. Total bytes written around 1Mb.
45  // Represented file size is about 190 Mb
46  // 23831 * (4 + 10 * 4) is close to 1Mb
47  TestCount _test_perf_write_sim_index_svfs(size_t count_vr, size_t count_lr, t_test_results &results) {
48  TestCount count;
50  std::string id = "ID";
51  svfs.insert(id, 12.0);
52  auto time_start = std::chrono::high_resolution_clock::now();
53 
54  for (size_t vr = 0; vr < count_vr; ++vr) {
55  t_fpos fpos = 80 + vr * 8004;
56  svfs.at(id).write(fpos, test_data_bytes_512, 4);
57  fpos += 4;
58  for (size_t lrsh = 0; lrsh < count_lr; ++lrsh) {
59  svfs.at(id).write(fpos, test_data_bytes_512, 4);
60  fpos += 8000 / count_lr;
61  }
62  }
63  std::ostringstream os;
64  os << "Sim SVFS:" << " vr=" << count_vr << " lr=" << count_lr;
65 
66  std::chrono::duration<double> time_exec = std::chrono::high_resolution_clock::now() - time_start;
67  auto result = TestResult(__PRETTY_FUNCTION__, os.str(), 0, "", time_exec.count(), svfs.at(id).num_bytes());
68  count.add_result(result.result());
69  results.push_back(result);
70  return count;
71  }
72 
73 
74  // Simulate writing a low level RP66V1 index. Total bytes written around 1Mb.
75  // Represented file size is about 190 Mb
76  // 23831 * (4 + 10 * 4) is close to 1Mb
78  TestCount count;
79  count += _test_perf_write_sim_index_svfs(1, 10, results);
80  count += _test_perf_write_sim_index_svfs(10, 10, results);
81  count += _test_perf_write_sim_index_svfs(100, 10, results);
82  count += _test_perf_write_sim_index_svfs(1000, 10, results);
83  count += _test_perf_write_sim_index_svfs(10000, 10, results);
84  count += _test_perf_write_sim_index_svfs(23831, 10, results);
85  count += _test_perf_write_sim_index_svfs(100000, 10, results);
86 // count += _test_perf_write_sim_index_svfs(1000000, 10, results);
87 
88 // SparseVirtualFileSystem svfs;
89 // std::string id = "ID";
90 // svfs.insert(id, 12.0);
91 // auto time_start = std::chrono::high_resolution_clock::now();
92 //
93 // for (size_t vr = 0; vr < 23831; ++vr) {
94 // t_fpos fpos = 80 + vr * 8004;
95 // svfs.at(id).write(fpos, test_data_bytes_512, 4);
96 // fpos += 4;
97 // for (int lrsh = 0; lrsh < 10; ++lrsh) {
98 // svfs.at(id).write(fpos, test_data_bytes_512, 4);
99 // fpos += 800;
100 // }
101 // }
102 //
103 // std::chrono::duration<double> time_exec = std::chrono::high_resolution_clock::now() - time_start;
104 // auto result = TestResult(__PRETTY_FUNCTION__, "Sim low level index on SVFS", 0, "", time_exec.count(), svfs.at(id).num_bytes());
105 // count.add_result(result.result());
106 // results.push_back(result);
107  return count;
108  }
109 
110 
112  TestCount count;
113  count += test_perf_write_sim_index_svfs(results);
114  return count;
115  }
116  } // namespace Test
117 } // namespace SVFS
size_t num_bytes() const noexcept
Gives exact number of data bytes held.
Definition: svf.h:351
void write(t_fpos fpos, const char *data, size_t len)
Write the data a the given file position.
Definition: svf.cpp:452
A SparseVirtualFileSystem is a key/value store where the key is a file ID as a string and the value i...
Definition: svfs.h:94
const SparseVirtualFile & at(const std::string &id) const
Return the const SparseVirtualFile at the given ID.
Definition: svfs.cpp:88
void insert(const std::string &id, double mod_time)
Inserts a new SparseVirtualFile corresponding to the given ID and file modification timestamp.
Definition: svfs.cpp:44
Count of tests taht pass and fail.
Definition: test.h:137
void add_result(int result)
Add a tests result.
Definition: test.h:148
Result of a test.
Definition: test.h:68
std::vector< TestResult > t_test_results
Definition: test.h:128
TestCount test_perf_write_sim_index_svfs(t_test_results &results)
Definition: test_svfs.cpp:77
TestCount _test_perf_write_sim_index_svfs(size_t count_vr, size_t count_lr, t_test_results &results)
Definition: test_svfs.cpp:47
TestCount test_svfs_all(t_test_results &results)
Definition: test_svfs.cpp:111
const char test_data_bytes_512[]
Definition: test.cpp:51
The namespace for all svfsc code.
Definition: svf.cpp:41
size_t t_fpos
Definition: svf.h:247