summaryrefslogtreecommitdiff
path: root/a2/measurement.cc
diff options
context:
space:
mode:
Diffstat (limited to 'a2/measurement.cc')
-rw-r--r--a2/measurement.cc41
1 files changed, 22 insertions, 19 deletions
diff --git a/a2/measurement.cc b/a2/measurement.cc
index cf90d52..c624bfa 100644
--- a/a2/measurement.cc
+++ b/a2/measurement.cc
@@ -1,11 +1,3 @@
-#if 0
-import <chrono>;
-import <vector>;
-import <iostream>;
-import <algorithm>;
-import <string>;
-import <thread>;
-#else
#include <chrono>
#include <vector>
#include <iostream>
@@ -13,7 +5,6 @@ import <thread>;
#include <string>
#include <thread>
#include <random>
-#endif
class Measure
{
@@ -51,7 +42,7 @@ int main()
using namespace std::chrono_literals;
// Sanity check measurement mechanism
- measure("Sanity check (sleep 100ms):",
+ measure("Sanity check (sleep 100ms)",
[]()
{
std::this_thread::sleep_for(100ms);
@@ -63,22 +54,28 @@ int main()
// * Find the 7 in the middle of a vector<int> where all other elements are
// not 7.
{
- std::vector<int> v(1'000'000, 42); // one million items with the int 42
+ std::vector<int> v(10'000'000, 42); // one million items with the int 42
v[v.size() / 2] = 7; // set middle item to 7
measure("std::find 7 in the middle",
[&v]()
{
- std::find(v.begin(), v.end(), 7);
+ if(std::find(v.begin(), v.end(), 7) == std::end(v))
+ {
+ std::cout << "That was unexpected!\n";
+ }
});
}
// * Try to find a 7 in a vector<int> where no element is 7
{
- std::vector<int> v(1'000'000, 42); // one million items with the int 42
+ std::vector<int> v(10'000'000, 42); // one million items with the int 42
measure("std::find 7 not there",
[&v]()
{
- std::find(v.begin(), v.end(), 7);
+ if(std::find(v.begin(), v.end(), 7) != std::end(v))
+ {
+ std::cout << "That was unexpected!\n";
+ }
});
}
@@ -88,22 +85,28 @@ int main()
// * Find the x < 7 in the middle of a vector<int> where all other elements
// are >= 7.
{
- std::vector<int> v(1'000'000, 42); // one million items with the int 42
+ std::vector<int> v(10'000'000, 42); // one million items with the int 42
v[v.size() / 2] = 5; // set middle item to 5
measure("std::find_if x < 7 in the middle",
[&v]()
{
- std::find_if(v.begin(), v.end(), [](int x){ return x < 7;});
+ if(std::find_if(v.begin(), v.end(), [](int x){ return x < 7;}) == std::end(v))
+ {
+ std::cout << "That was unexpected!\n";
+ }
});
}
// * Try to find an x < 7 in a vector<int> where all elements are >= 7.
{
- std::vector<int> v(1'000'000, 42); // one million items with the int 42
+ std::vector<int> v(10'000'000, 42); // one million items with the int 42
measure("std::find_if x < 7 not there",
[&v]()
{
- std::find_if(v.begin(), v.end(), [](int x){ return x < 7;});
+ if(std::find_if(v.begin(), v.end(), [](int x){ return x < 7;}) != std::end(v))
+ {
+ std::cout << "That was unexpected!\n";
+ }
});
}
@@ -116,7 +119,7 @@ int main()
std::uniform_int_distribution<char> distrib('A', 'Z');
std::vector<std::string> vs;
- vs.resize(1'000'000);
+ vs.resize(10'000'000);
for(auto &str: vs)
{
str.reserve(20);