summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2023-06-05 01:56:37 +0800
committerKunoiSayami <[email protected]>2023-06-05 01:56:37 +0800
commit5f38ca067108eea5a8c334bd8cbe5866300d585c (patch)
tree76e477e0030ffb585bd1cc8bf973017dc4b28885
parent155b3a832c590c55ea3d89dd0783713f1d0f19c1 (diff)
feat: Optimize output
Signed-off-by: KunoiSayami <[email protected]>
-rw-r--r--expt_0604.cpp10
-rw-r--r--read_helper.h6
2 files changed, 7 insertions, 9 deletions
diff --git a/expt_0604.cpp b/expt_0604.cpp
index 9217f9e..a1dbf26 100644
--- a/expt_0604.cpp
+++ b/expt_0604.cpp
@@ -1,4 +1,4 @@
-// Experimental content: Test fstream vs stdio
+// Experimental content: Test fstream vs stdio read file
#include <cassert>
#include <chrono>
@@ -17,7 +17,7 @@ void stdio() {
assert(file);
auto read_count = 0L;
for (unsigned long long l;
- read_count < limit && fscanf(file, "%lld ", &l) != EOF;)
+ read_count < limit && fscanf(file, "%llu ", &l) != EOF;)
read_count++;
fclose(file);
}
@@ -36,8 +36,8 @@ auto measure(const char *function_name, void (*test_function)()) {
auto end = std::chrono::high_resolution_clock ::now();
auto duration = end - start;
std::cout << "Function: " << std::fixed << std::setprecision(3)
- << function_name << " " << (double)duration.count() / 1000.0 << "ms"
- << std::endl;
+ << function_name << " " << (double)duration.count() / 1000.0
+ << "ms\n";
return duration.count();
}
@@ -54,5 +54,5 @@ int main(int argc, char const *argv[]) {
}
auto s = measure("stdio", stdio);
auto f = measure("fstream", fstream);
- std::cout << (s > f ? "stdio" : "fstream") << "win";
+ std::cout << (s < f ? "stdio" : "fstream") << " win\n";
}
diff --git a/read_helper.h b/read_helper.h
index f4615d4..baf0781 100644
--- a/read_helper.h
+++ b/read_helper.h
@@ -49,9 +49,7 @@ public:
size_t population_length, size_t total_row = 0)
: filename(filename), sample_length(sample_length),
population_length(population_length),
- random_number(genRandomRow(total_row)) {
- // printf("%zu %zu\n", sample_length, needed_read_length);
- }
+ random_number(genRandomRow(total_row)) {}
key_type maxValue() const { return max_value; }
key_type minValue() const { return min_value; }
@@ -82,7 +80,6 @@ public:
if (random_number > 0) {
P_ERR("\rReading skip");
- // fprintf(stderr, "Skip %lu\n", read_number);
read_number = random_number;
for (key_type i; read_number > 0 && !fin.eof(); fin >> i)
read_number--;
@@ -96,6 +93,7 @@ public:
fin >> i;
read_number++;
}
+
fin.close();
P_ERR("\r");
return true;