You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.0 KiB

#include "benchmark-shared-unique.h"
#include "measure_time.h"
#include "make_unique.h"
#define COUNT (1u << 26)
void benchmark_forward_empty_raw() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_raw(nullptr);
}
}
void benchmark_forward_empty_unique() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_unique({});
}
}
void benchmark_forward_empty_shared() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_shared({});
}
}
void benchmark_forward_empty_shared_from_unique() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_shared(std::unique_ptr<size_t>{});
}
}
void benchmark_forward_new_raw() {
for (size_t i = 0; i < COUNT; ++i) {
size_t* p = new size_t{i};
(void) forward_raw(p);
delete p;
}
}
void benchmark_forward_new_unique() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_unique(std::make_unique<size_t>(i));
}
}
void benchmark_forward_new_shared() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_shared(std::make_shared<size_t>(i));
}
}
void benchmark_forward_new_shared_from_unique() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_shared(std::make_unique<size_t>(i));
}
}
void benchmark_forward_new_raw_large() {
for (size_t i = 0; i < COUNT; ++i) {
Large* p = new Large{i};
(void) forward_raw(p);
delete p;
}
}
void benchmark_forward_new_unique_large() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_unique_large(std::make_unique<Large>(i));
}
}
void benchmark_forward_new_shared_large() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_shared_large(std::make_shared<Large>(i));
}
}
void benchmark_forward_new_shared_large_from_unique() {
for (size_t i = 0; i < COUNT; ++i) {
(void) forward_shared_large(std::make_unique<Large>(i));
}
}
int main() {
std::cout << "forward empty raw : ";
measure_time(benchmark_forward_empty_raw);
std::cout << "forward empty unique : ";
measure_time(benchmark_forward_empty_unique);
std::cout << "forward empty shared : ";
measure_time(benchmark_forward_empty_shared);
std::cout << "forward empty shared from unique : ";
measure_time(benchmark_forward_empty_shared_from_unique);
std::cout << "\n";
std::cout << "forward new raw : ";
measure_time(benchmark_forward_new_raw);
std::cout << "forward new unique : ";
measure_time(benchmark_forward_new_unique);
std::cout << "forward new shared : ";
measure_time(benchmark_forward_new_shared);
std::cout << "forward new shared from unique : ";
measure_time(benchmark_forward_new_shared_from_unique);
std::cout << "\n";
std::cout << "forward new raw large : ";
measure_time(benchmark_forward_new_raw_large);
std::cout << "forward new unique large : ";
measure_time(benchmark_forward_new_unique_large);
std::cout << "forward new shared large : ";
measure_time(benchmark_forward_new_shared_large);
std::cout << "forward new shared large from unique: ";
measure_time(benchmark_forward_new_shared_large_from_unique);
}