Index: benchmarks/shared_ptr_create_destroy.cpp =================================================================== --- /dev/null +++ benchmarks/shared_ptr_create_destroy.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include + +void clobber() +{ + asm volatile("" : : : "memory"); +} + +std::atomic g_int; +std::atomic g_other; + +int main() { + auto a = std::chrono::high_resolution_clock::now(); + { + clobber(); + for (int i = 0; i < 1000000000; ++i) + { + auto sp = std::make_shared(g_int.load(std::memory_order_relaxed)); + g_other.store(*sp, std::memory_order_relaxed); + } + clobber(); + } + auto b = std::chrono::high_resolution_clock::now(); + std::cout<(b - a).count()/1000000000.0<<" seconds"< +#include +#include +#include + +void clobber() +{ + asm volatile("" : : : "memory"); +} + +std::atomic g_int; +std::atomic g_other; + +int main() { + auto a = std::chrono::high_resolution_clock::now(); + auto sp = std::make_shared(g_int.load(std::memory_order_relaxed)); + { + clobber(); + for (int i = 0; i < 1000000000; ++i) + { + std::shared_ptr sp2(sp); + g_other.store(*sp2, std::memory_order_relaxed); + } + clobber(); + } + auto b = std::chrono::high_resolution_clock::now(); + std::cout<(b - a).count()/1000000000.0<<" seconds"<