Skip to content

Instantly share code, notes, and snippets.

@303248153
Last active March 12, 2018 01:04
Show Gist options
  • Save 303248153/1bdde0e1aac210c00e0d1e590e73d2e3 to your computer and use it in GitHub Desktop.
Save 303248153/1bdde0e1aac210c00e0d1e590e73d2e3 to your computer and use it in GitHub Desktop.
#include <memory>
#include <atomic>
namespace {
class AImpl {
public:
void test() { ++value; }
std::atomic_int value;
};
class A {
public:
__attribute__((noinline))
void test() { impl_->test(); }
A(std::unique_ptr<AImpl> impl) : impl_(std::move(impl)) { }
std::unique_ptr<AImpl> impl_;
};
class BData {
public:
std::atomic_int value;
};
class B {
public:
__attribute__((noinline))
void test() { ++data_->value; }
B(std::unique_ptr<BData> data) : data_(std::move(data)) { }
std::unique_ptr<BData> data_;
};
}
int main() {
// A inst(std::make_unique<AImpl>());
B inst(std::make_unique<BData>());
for (std::size_t i = 0; i < 100000000; ++i) {
inst.test();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment