mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Fix wrong namespacing of benchmarking constructor helpers
This commit is contained in:
parent
ad3f50bbc1
commit
0fbf4f3e15
@ -185,19 +185,17 @@ construct and destroy objects without dynamic allocation and in a way that lets
|
|||||||
you measure construction and destruction separately.
|
you measure construction and destruction separately.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
BENCHMARK_ADVANCED("construct")(Catch::Benchmark::Chronometer meter)
|
BENCHMARK_ADVANCED("construct")(Catch::Benchmark::Chronometer meter) {
|
||||||
{
|
|
||||||
std::vector<Catch::Benchmark::storage_for<std::string>> storage(meter.runs());
|
std::vector<Catch::Benchmark::storage_for<std::string>> storage(meter.runs());
|
||||||
meter.measure([&](int i) { storage[i].construct("thing"); });
|
meter.measure([&](int i) { storage[i].construct("thing"); });
|
||||||
})
|
};
|
||||||
|
|
||||||
BENCHMARK_ADVANCED("destroy", [](Catch::Benchmark::Chronometer meter)
|
BENCHMARK_ADVANCED("destroy")(Catch::Benchmark::Chronometer meter) {
|
||||||
{
|
|
||||||
std::vector<Catch::Benchmark::destructable_object<std::string>> storage(meter.runs());
|
std::vector<Catch::Benchmark::destructable_object<std::string>> storage(meter.runs());
|
||||||
for(auto&& o : storage)
|
for(auto&& o : storage)
|
||||||
o.construct("thing");
|
o.construct("thing");
|
||||||
meter.measure([&](int i) { storage[i].destruct(); });
|
meter.measure([&](int i) { storage[i].destruct(); });
|
||||||
})
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
`Catch::Benchmark::storage_for<T>` objects are just pieces of raw storage suitable for `T`
|
`Catch::Benchmark::storage_for<T>` objects are just pieces of raw storage suitable for `T`
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
namespace Benchmark {
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
template <typename T, bool Destruct>
|
template <typename T, bool Destruct>
|
||||||
struct ObjectStorage
|
struct ObjectStorage
|
||||||
@ -61,13 +62,14 @@ namespace Catch {
|
|||||||
|
|
||||||
TStorage data;
|
TStorage data;
|
||||||
};
|
};
|
||||||
}
|
} // namespace Detail
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using storage_for = Detail::ObjectStorage<T, true>;
|
using storage_for = Detail::ObjectStorage<T, true>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using destructable_object = Detail::ObjectStorage<T, false>;
|
using destructable_object = Detail::ObjectStorage<T, false>;
|
||||||
}
|
} // namespace Benchmark
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_CONSTRUCTOR_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CONSTRUCTOR_HPP_INCLUDED
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <catch2/benchmark/catch_benchmark.hpp>
|
#include <catch2/benchmark/catch_benchmark.hpp>
|
||||||
|
#include <catch2/benchmark/catch_constructor.hpp>
|
||||||
#include <catch2/catch_generators_specific.hpp>
|
#include <catch2/catch_generators_specific.hpp>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -127,4 +128,18 @@ TEST_CASE("Benchmark containers", "[!benchmark]") {
|
|||||||
REQUIRE(v[i] == generated);
|
REQUIRE(v[i] == generated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("construct and destroy example") {
|
||||||
|
BENCHMARK_ADVANCED("construct")(Catch::Benchmark::Chronometer meter) {
|
||||||
|
std::vector<Catch::Benchmark::storage_for<std::string>> storage(meter.runs());
|
||||||
|
meter.measure([&](int i) { storage[i].construct("thing"); });
|
||||||
|
};
|
||||||
|
|
||||||
|
BENCHMARK_ADVANCED("destroy")(Catch::Benchmark::Chronometer meter) {
|
||||||
|
std::vector<Catch::Benchmark::destructable_object<std::string>> storage(meter.runs());
|
||||||
|
for(auto&& o : storage)
|
||||||
|
o.construct("thing");
|
||||||
|
meter.measure([&](int i) { storage[i].destruct(); });
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user