haikuwebkit/PerformanceTests/MallocBench/MallocBench/medium.cpp

74 lines
2.5 KiB
C++
Raw Permalink Normal View History

Let's benchmark malloc https://bugs.webkit.org/show_bug.cgi?id=131118 Reviewed by Mark Hahnenberg. I want to replace fastMalloc with something faster (fasterMalloc?). I wrote these benchmarks to test / drive development. * MallocBench: Added. * MallocBench/MallocBench: Added. * MallocBench/MallocBench.xcodeproj: Added. * MallocBench/MallocBench.xcodeproj/project.pbxproj: Added. * MallocBench/MallocBench/Benchmark.cpp: Added. (allocateHeap): (deallocateHeap): (Benchmark::Benchmark): (Benchmark::printBenchmarks): (Benchmark::runOnce): (Benchmark::run): (Benchmark::printReport): (Benchmark::currentTimeMS): (Benchmark::currentMemoryBytes): * MallocBench/MallocBench/Benchmark.h: Added. (Benchmark::Memory::Memory): (Benchmark::Memory::operator-): (Benchmark::isValid): * MallocBench/MallocBench/CPUCount.cpp: Added. (cpuCount): * MallocBench/MallocBench/CPUCount.h: Added. * MallocBench/MallocBench/CommandLine.cpp: Added. (CommandLine::printUsage): * MallocBench/MallocBench/CommandLine.h: Added. (CommandLine::isValid): (CommandLine::benchmarkName): (CommandLine::isParallel): (CommandLine::heapSize): (CommandLine::measureHeap): * MallocBench/MallocBench/Interpreter.cpp: Added. (Interpreter::Interpreter): (Interpreter::~Interpreter): (Interpreter::run): * MallocBench/MallocBench/Interpreter.h: Added. * MallocBench/MallocBench/balloon.cpp: Added. (benchmark_balloon): * MallocBench/MallocBench/balloon.h: Added. * MallocBench/MallocBench/big.cpp: Added. (benchmark_big): * MallocBench/MallocBench/big.h: Added. * MallocBench/MallocBench/churn.cpp: Added. (HeapDouble::operator new): (HeapDouble::operator delete): (HeapDouble::HeapDouble): (HeapDouble::operator+=): (benchmark_churn): * MallocBench/MallocBench/churn.h: Added. * MallocBench/MallocBench/crash.ops: Added. * MallocBench/MallocBench/facebook.cpp: Added. (benchmark_facebook): * MallocBench/MallocBench/facebook.h: Added. * MallocBench/MallocBench/facebook.ops: Added. * MallocBench/MallocBench/fragment.cpp: Added. (validate): (benchmark_fragment): (benchmark_fragment_iterate): * MallocBench/MallocBench/fragment.h: Added. * MallocBench/MallocBench/list.cpp: Added. (benchmark_list_allocate): (benchmark_list_traverse): * MallocBench/MallocBench/list.h: Added. * MallocBench/MallocBench/main.cpp: Added. (main): * MallocBench/MallocBench/mbmalloc.cpp: Added. * MallocBench/MallocBench/mbmalloc.h: Added. * MallocBench/MallocBench/medium.cpp: Added. (benchmark_medium): * MallocBench/MallocBench/medium.h: Added. * MallocBench/MallocBench/message.cpp: Added. (benchmark_message_one): (benchmark_message_many): * MallocBench/MallocBench/message.h: Added. * MallocBench/MallocBench/realloc.cpp: Added. (benchmark_realloc): * MallocBench/MallocBench/realloc.h: Added. * MallocBench/MallocBench/tree.cpp: Added. (benchmark_tree_allocate): (benchmark_tree_traverse): (benchmark_tree_churn): * MallocBench/MallocBench/tree.h: Added. * MallocBench/run-malloc-benchmarks: Added. Canonical link: https://commits.webkit.org/149171@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-02 21:38:49 +00:00
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "CPUCount.h"
#include "medium.h"
#include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <string.h>
Let's benchmark malloc https://bugs.webkit.org/show_bug.cgi?id=131118 Reviewed by Mark Hahnenberg. I want to replace fastMalloc with something faster (fasterMalloc?). I wrote these benchmarks to test / drive development. * MallocBench: Added. * MallocBench/MallocBench: Added. * MallocBench/MallocBench.xcodeproj: Added. * MallocBench/MallocBench.xcodeproj/project.pbxproj: Added. * MallocBench/MallocBench/Benchmark.cpp: Added. (allocateHeap): (deallocateHeap): (Benchmark::Benchmark): (Benchmark::printBenchmarks): (Benchmark::runOnce): (Benchmark::run): (Benchmark::printReport): (Benchmark::currentTimeMS): (Benchmark::currentMemoryBytes): * MallocBench/MallocBench/Benchmark.h: Added. (Benchmark::Memory::Memory): (Benchmark::Memory::operator-): (Benchmark::isValid): * MallocBench/MallocBench/CPUCount.cpp: Added. (cpuCount): * MallocBench/MallocBench/CPUCount.h: Added. * MallocBench/MallocBench/CommandLine.cpp: Added. (CommandLine::printUsage): * MallocBench/MallocBench/CommandLine.h: Added. (CommandLine::isValid): (CommandLine::benchmarkName): (CommandLine::isParallel): (CommandLine::heapSize): (CommandLine::measureHeap): * MallocBench/MallocBench/Interpreter.cpp: Added. (Interpreter::Interpreter): (Interpreter::~Interpreter): (Interpreter::run): * MallocBench/MallocBench/Interpreter.h: Added. * MallocBench/MallocBench/balloon.cpp: Added. (benchmark_balloon): * MallocBench/MallocBench/balloon.h: Added. * MallocBench/MallocBench/big.cpp: Added. (benchmark_big): * MallocBench/MallocBench/big.h: Added. * MallocBench/MallocBench/churn.cpp: Added. (HeapDouble::operator new): (HeapDouble::operator delete): (HeapDouble::HeapDouble): (HeapDouble::operator+=): (benchmark_churn): * MallocBench/MallocBench/churn.h: Added. * MallocBench/MallocBench/crash.ops: Added. * MallocBench/MallocBench/facebook.cpp: Added. (benchmark_facebook): * MallocBench/MallocBench/facebook.h: Added. * MallocBench/MallocBench/facebook.ops: Added. * MallocBench/MallocBench/fragment.cpp: Added. (validate): (benchmark_fragment): (benchmark_fragment_iterate): * MallocBench/MallocBench/fragment.h: Added. * MallocBench/MallocBench/list.cpp: Added. (benchmark_list_allocate): (benchmark_list_traverse): * MallocBench/MallocBench/list.h: Added. * MallocBench/MallocBench/main.cpp: Added. (main): * MallocBench/MallocBench/mbmalloc.cpp: Added. * MallocBench/MallocBench/mbmalloc.h: Added. * MallocBench/MallocBench/medium.cpp: Added. (benchmark_medium): * MallocBench/MallocBench/medium.h: Added. * MallocBench/MallocBench/message.cpp: Added. (benchmark_message_one): (benchmark_message_many): * MallocBench/MallocBench/message.h: Added. * MallocBench/MallocBench/realloc.cpp: Added. (benchmark_realloc): * MallocBench/MallocBench/realloc.h: Added. * MallocBench/MallocBench/tree.cpp: Added. (benchmark_tree_allocate): (benchmark_tree_traverse): (benchmark_tree_churn): * MallocBench/MallocBench/tree.h: Added. * MallocBench/run-malloc-benchmarks: Added. Canonical link: https://commits.webkit.org/149171@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-02 21:38:49 +00:00
#include <strings.h>
#include "mbmalloc.h"
using namespace std;
struct Object {
double* p;
size_t size;
};
MallocBench: Added recording for nimlang website, new recording details and added new options https://bugs.webkit.org/show_bug.cgi?id=154485 Reviewed by Geoff Garen. Added new capabilities to MallocBench. These include: Added a recording of http://nim-lang.org/docs/lib.html. Added thread id to the recording and the ability to playback switching threads in MallocBench Added aligned allocations to recordings and the ability to playback Added --use-thread-id option to honor recorded thread ids Added --detailed-report to output remaining allocations by size after playback Added --no-warmup to not run the warm up iteration Changed the way that options are passed down to the benchmarks. Instead of passing individual boolean or numeric option values, just pass a reference the CommandLine itself. Each benchmark can access the options that are appropriate. The Benchmark class also uses the options for is parallel, run counts and warm up. Added thread id and aligned malloc to the Op by noticing that structure padding and Opcode allowed for another 32 bits of data. Breaking that unused 32 bits into a 16 bit thread id value and a 16 bit log base 2 of the alignment for aligned malloc allowed for existing recordings to playback without any incompatibilities. Threaded operation is simulated by creating threads as needed. As long as the next Op's thread id is the same as the last, operation continues as normal. When the next Op has a different thread id, we switch to that thread using the shared Op stream to continue playing back. There is a mutex to assure that only one thread is really running at a time and a condition variable used to wait that the current thread id matches each block thread's thread id. This doesn't simulate true concurrent threading, but is instead plays back Ops recorded for multiple thread faithfully. * MallocBench/MallocBench.xcodeproj/project.pbxproj: * MallocBench/MallocBench/Benchmark.cpp: (deallocateHeap): (Benchmark::Benchmark): (Benchmark::runOnce): (Benchmark::run): * MallocBench/MallocBench/Benchmark.h: (Benchmark::isValid): * MallocBench/MallocBench/CommandLine.cpp: (CommandLine::printUsage): * MallocBench/MallocBench/CommandLine.h: (CommandLine::isValid): (CommandLine::benchmarkName): (CommandLine::isParallel): (CommandLine::useThreadID): (CommandLine::detailedReport): (CommandLine::warmUp): (CommandLine::heapSize): (CommandLine::runs): * MallocBench/MallocBench/Interpreter.cpp: (Interpreter::Interpreter): (Interpreter::run): (Interpreter::readOps): (Interpreter::doOnSameThread): (Interpreter::switchToThread): (Interpreter::detailedReport): (compute2toPower): (writeData): (Interpreter::doMallocOp): (Interpreter::Thread::Thread): (Interpreter::Thread::stop): (Interpreter::Thread::~Thread): (Interpreter::Thread::runThread): (Interpreter::Thread::waitToRun): (Interpreter::Thread::switchTo): * MallocBench/MallocBench/Interpreter.h: (Interpreter::Thread::isMainThread): * MallocBench/MallocBench/alloc_free.cpp: Added. (benchmark_alloc_free): * MallocBench/MallocBench/alloc_free.h: Added. * MallocBench/MallocBench/balloon.cpp: (benchmark_balloon): * MallocBench/MallocBench/balloon.h: * MallocBench/MallocBench/big.cpp: (benchmark_big): * MallocBench/MallocBench/big.h: * MallocBench/MallocBench/churn.cpp: (benchmark_churn): * MallocBench/MallocBench/churn.h: * MallocBench/MallocBench/facebook.cpp: (benchmark_facebook): * MallocBench/MallocBench/facebook.h: * MallocBench/MallocBench/flickr.cpp: (benchmark_flickr): (benchmark_flickr_memory_warning): * MallocBench/MallocBench/flickr.h: * MallocBench/MallocBench/fragment.cpp: (validate): (benchmark_fragment): (benchmark_fragment_iterate): * MallocBench/MallocBench/fragment.h: * MallocBench/MallocBench/list.cpp: (benchmark_list_allocate): (benchmark_list_traverse): * MallocBench/MallocBench/list.h: * MallocBench/MallocBench/main.cpp: (main): * MallocBench/MallocBench/medium.cpp: (benchmark_medium): * MallocBench/MallocBench/medium.h: * MallocBench/MallocBench/memalign.cpp: (test): (benchmark_memalign): * MallocBench/MallocBench/memalign.h: * MallocBench/MallocBench/message.cpp: (benchmark_message_one): (benchmark_message_many): * MallocBench/MallocBench/message.h: * MallocBench/MallocBench/nimlang.cpp: Added. (benchmark_nimlang): * MallocBench/MallocBench/nimlang.h: Added. * MallocBench/MallocBench/nimlang.ops: Added. * MallocBench/MallocBench/realloc.cpp: (benchmark_realloc): * MallocBench/MallocBench/realloc.h: * MallocBench/MallocBench/reddit.cpp: (benchmark_reddit): (benchmark_reddit_memory_warning): * MallocBench/MallocBench/reddit.h: * MallocBench/MallocBench/stress.cpp: (deallocate): (benchmark_stress): * MallocBench/MallocBench/stress.h: * MallocBench/MallocBench/stress_aligned.cpp: (benchmark_stress_aligned): * MallocBench/MallocBench/stress_aligned.h: * MallocBench/MallocBench/theverge.cpp: (benchmark_theverge): (benchmark_theverge_memory_warning): * MallocBench/MallocBench/theverge.h: * MallocBench/MallocBench/tree.cpp: (benchmark_tree_allocate): (benchmark_tree_traverse): (benchmark_tree_churn): * MallocBench/MallocBench/tree.h: * MallocBench/run-malloc-benchmarks: Canonical link: https://commits.webkit.org/172661@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196955 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-22 22:02:24 +00:00
void benchmark_medium(CommandLine& commandLine)
Let's benchmark malloc https://bugs.webkit.org/show_bug.cgi?id=131118 Reviewed by Mark Hahnenberg. I want to replace fastMalloc with something faster (fasterMalloc?). I wrote these benchmarks to test / drive development. * MallocBench: Added. * MallocBench/MallocBench: Added. * MallocBench/MallocBench.xcodeproj: Added. * MallocBench/MallocBench.xcodeproj/project.pbxproj: Added. * MallocBench/MallocBench/Benchmark.cpp: Added. (allocateHeap): (deallocateHeap): (Benchmark::Benchmark): (Benchmark::printBenchmarks): (Benchmark::runOnce): (Benchmark::run): (Benchmark::printReport): (Benchmark::currentTimeMS): (Benchmark::currentMemoryBytes): * MallocBench/MallocBench/Benchmark.h: Added. (Benchmark::Memory::Memory): (Benchmark::Memory::operator-): (Benchmark::isValid): * MallocBench/MallocBench/CPUCount.cpp: Added. (cpuCount): * MallocBench/MallocBench/CPUCount.h: Added. * MallocBench/MallocBench/CommandLine.cpp: Added. (CommandLine::printUsage): * MallocBench/MallocBench/CommandLine.h: Added. (CommandLine::isValid): (CommandLine::benchmarkName): (CommandLine::isParallel): (CommandLine::heapSize): (CommandLine::measureHeap): * MallocBench/MallocBench/Interpreter.cpp: Added. (Interpreter::Interpreter): (Interpreter::~Interpreter): (Interpreter::run): * MallocBench/MallocBench/Interpreter.h: Added. * MallocBench/MallocBench/balloon.cpp: Added. (benchmark_balloon): * MallocBench/MallocBench/balloon.h: Added. * MallocBench/MallocBench/big.cpp: Added. (benchmark_big): * MallocBench/MallocBench/big.h: Added. * MallocBench/MallocBench/churn.cpp: Added. (HeapDouble::operator new): (HeapDouble::operator delete): (HeapDouble::HeapDouble): (HeapDouble::operator+=): (benchmark_churn): * MallocBench/MallocBench/churn.h: Added. * MallocBench/MallocBench/crash.ops: Added. * MallocBench/MallocBench/facebook.cpp: Added. (benchmark_facebook): * MallocBench/MallocBench/facebook.h: Added. * MallocBench/MallocBench/facebook.ops: Added. * MallocBench/MallocBench/fragment.cpp: Added. (validate): (benchmark_fragment): (benchmark_fragment_iterate): * MallocBench/MallocBench/fragment.h: Added. * MallocBench/MallocBench/list.cpp: Added. (benchmark_list_allocate): (benchmark_list_traverse): * MallocBench/MallocBench/list.h: Added. * MallocBench/MallocBench/main.cpp: Added. (main): * MallocBench/MallocBench/mbmalloc.cpp: Added. * MallocBench/MallocBench/mbmalloc.h: Added. * MallocBench/MallocBench/medium.cpp: Added. (benchmark_medium): * MallocBench/MallocBench/medium.h: Added. * MallocBench/MallocBench/message.cpp: Added. (benchmark_message_one): (benchmark_message_many): * MallocBench/MallocBench/message.h: Added. * MallocBench/MallocBench/realloc.cpp: Added. (benchmark_realloc): * MallocBench/MallocBench/realloc.h: Added. * MallocBench/MallocBench/tree.cpp: Added. (benchmark_tree_allocate): (benchmark_tree_traverse): (benchmark_tree_churn): * MallocBench/MallocBench/tree.h: Added. * MallocBench/run-malloc-benchmarks: Added. Canonical link: https://commits.webkit.org/149171@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-02 21:38:49 +00:00
{
size_t times = 1;
size_t vmSize = 1ul * 1024 * 1024 * 1024;
bmalloc: Misc improvements to MallocBench https://bugs.webkit.org/show_bug.cgi?id=157004 Reviewed by Darin Adler. * MallocBench/run-malloc-benchmarks: Added --memory and --memory_warning modes for focused memory testing. * MallocBench/MallocBench/Benchmark.cpp: (Benchmark::printReport): Clarified output. (Benchmark::currentMemoryBytes): Added compressed memory because top does the same. (It always happens to zero in the benchmarks we run. But this is good for sanity.) * MallocBench/MallocBench/CommandLine.cpp: Moved up to 8 runs to reduce variance. * MallocBench/MallocBench/alloc_free.cpp: (benchmark_alloc_free): Cycle a single allocation in order to stress the effect of merging on calls to madvise. * MallocBench/MallocBench/big.cpp: (benchmark_big): Graduated to 8kB-128kB because medium tests up to 8 and our large allocator doesn't kick in until 64kB. * MallocBench/MallocBench/medium.cpp: (benchmark_medium): Test all the way down to 1kB because our large allocator used to service 1kB allocations and 1kB is an interesting middle size where memory is unusually large but allocation throughput still matters. * MallocBench/MallocBench/stress.cpp: (benchmark_stress): Reduced the churn count to match stress_aligned because this test was taking too long to complete. * MallocBench/MallocBench/stress_aligned.cpp: (benchmark_stress_aligned): Our new large allocator can handle even more absurdly large values. Canonical link: https://commits.webkit.org/175116@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200060 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-04-25 23:50:25 +00:00
size_t objectSizeMin = 1 * 1024;
Let's benchmark malloc https://bugs.webkit.org/show_bug.cgi?id=131118 Reviewed by Mark Hahnenberg. I want to replace fastMalloc with something faster (fasterMalloc?). I wrote these benchmarks to test / drive development. * MallocBench: Added. * MallocBench/MallocBench: Added. * MallocBench/MallocBench.xcodeproj: Added. * MallocBench/MallocBench.xcodeproj/project.pbxproj: Added. * MallocBench/MallocBench/Benchmark.cpp: Added. (allocateHeap): (deallocateHeap): (Benchmark::Benchmark): (Benchmark::printBenchmarks): (Benchmark::runOnce): (Benchmark::run): (Benchmark::printReport): (Benchmark::currentTimeMS): (Benchmark::currentMemoryBytes): * MallocBench/MallocBench/Benchmark.h: Added. (Benchmark::Memory::Memory): (Benchmark::Memory::operator-): (Benchmark::isValid): * MallocBench/MallocBench/CPUCount.cpp: Added. (cpuCount): * MallocBench/MallocBench/CPUCount.h: Added. * MallocBench/MallocBench/CommandLine.cpp: Added. (CommandLine::printUsage): * MallocBench/MallocBench/CommandLine.h: Added. (CommandLine::isValid): (CommandLine::benchmarkName): (CommandLine::isParallel): (CommandLine::heapSize): (CommandLine::measureHeap): * MallocBench/MallocBench/Interpreter.cpp: Added. (Interpreter::Interpreter): (Interpreter::~Interpreter): (Interpreter::run): * MallocBench/MallocBench/Interpreter.h: Added. * MallocBench/MallocBench/balloon.cpp: Added. (benchmark_balloon): * MallocBench/MallocBench/balloon.h: Added. * MallocBench/MallocBench/big.cpp: Added. (benchmark_big): * MallocBench/MallocBench/big.h: Added. * MallocBench/MallocBench/churn.cpp: Added. (HeapDouble::operator new): (HeapDouble::operator delete): (HeapDouble::HeapDouble): (HeapDouble::operator+=): (benchmark_churn): * MallocBench/MallocBench/churn.h: Added. * MallocBench/MallocBench/crash.ops: Added. * MallocBench/MallocBench/facebook.cpp: Added. (benchmark_facebook): * MallocBench/MallocBench/facebook.h: Added. * MallocBench/MallocBench/facebook.ops: Added. * MallocBench/MallocBench/fragment.cpp: Added. (validate): (benchmark_fragment): (benchmark_fragment_iterate): * MallocBench/MallocBench/fragment.h: Added. * MallocBench/MallocBench/list.cpp: Added. (benchmark_list_allocate): (benchmark_list_traverse): * MallocBench/MallocBench/list.h: Added. * MallocBench/MallocBench/main.cpp: Added. (main): * MallocBench/MallocBench/mbmalloc.cpp: Added. * MallocBench/MallocBench/mbmalloc.h: Added. * MallocBench/MallocBench/medium.cpp: Added. (benchmark_medium): * MallocBench/MallocBench/medium.h: Added. * MallocBench/MallocBench/message.cpp: Added. (benchmark_message_one): (benchmark_message_many): * MallocBench/MallocBench/message.h: Added. * MallocBench/MallocBench/realloc.cpp: Added. (benchmark_realloc): * MallocBench/MallocBench/realloc.h: Added. * MallocBench/MallocBench/tree.cpp: Added. (benchmark_tree_allocate): (benchmark_tree_traverse): (benchmark_tree_churn): * MallocBench/MallocBench/tree.h: Added. * MallocBench/run-malloc-benchmarks: Added. Canonical link: https://commits.webkit.org/149171@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-02 21:38:49 +00:00
size_t objectSizeMax = 8 * 1024;
MallocBench: Added recording for nimlang website, new recording details and added new options https://bugs.webkit.org/show_bug.cgi?id=154485 Reviewed by Geoff Garen. Added new capabilities to MallocBench. These include: Added a recording of http://nim-lang.org/docs/lib.html. Added thread id to the recording and the ability to playback switching threads in MallocBench Added aligned allocations to recordings and the ability to playback Added --use-thread-id option to honor recorded thread ids Added --detailed-report to output remaining allocations by size after playback Added --no-warmup to not run the warm up iteration Changed the way that options are passed down to the benchmarks. Instead of passing individual boolean or numeric option values, just pass a reference the CommandLine itself. Each benchmark can access the options that are appropriate. The Benchmark class also uses the options for is parallel, run counts and warm up. Added thread id and aligned malloc to the Op by noticing that structure padding and Opcode allowed for another 32 bits of data. Breaking that unused 32 bits into a 16 bit thread id value and a 16 bit log base 2 of the alignment for aligned malloc allowed for existing recordings to playback without any incompatibilities. Threaded operation is simulated by creating threads as needed. As long as the next Op's thread id is the same as the last, operation continues as normal. When the next Op has a different thread id, we switch to that thread using the shared Op stream to continue playing back. There is a mutex to assure that only one thread is really running at a time and a condition variable used to wait that the current thread id matches each block thread's thread id. This doesn't simulate true concurrent threading, but is instead plays back Ops recorded for multiple thread faithfully. * MallocBench/MallocBench.xcodeproj/project.pbxproj: * MallocBench/MallocBench/Benchmark.cpp: (deallocateHeap): (Benchmark::Benchmark): (Benchmark::runOnce): (Benchmark::run): * MallocBench/MallocBench/Benchmark.h: (Benchmark::isValid): * MallocBench/MallocBench/CommandLine.cpp: (CommandLine::printUsage): * MallocBench/MallocBench/CommandLine.h: (CommandLine::isValid): (CommandLine::benchmarkName): (CommandLine::isParallel): (CommandLine::useThreadID): (CommandLine::detailedReport): (CommandLine::warmUp): (CommandLine::heapSize): (CommandLine::runs): * MallocBench/MallocBench/Interpreter.cpp: (Interpreter::Interpreter): (Interpreter::run): (Interpreter::readOps): (Interpreter::doOnSameThread): (Interpreter::switchToThread): (Interpreter::detailedReport): (compute2toPower): (writeData): (Interpreter::doMallocOp): (Interpreter::Thread::Thread): (Interpreter::Thread::stop): (Interpreter::Thread::~Thread): (Interpreter::Thread::runThread): (Interpreter::Thread::waitToRun): (Interpreter::Thread::switchTo): * MallocBench/MallocBench/Interpreter.h: (Interpreter::Thread::isMainThread): * MallocBench/MallocBench/alloc_free.cpp: Added. (benchmark_alloc_free): * MallocBench/MallocBench/alloc_free.h: Added. * MallocBench/MallocBench/balloon.cpp: (benchmark_balloon): * MallocBench/MallocBench/balloon.h: * MallocBench/MallocBench/big.cpp: (benchmark_big): * MallocBench/MallocBench/big.h: * MallocBench/MallocBench/churn.cpp: (benchmark_churn): * MallocBench/MallocBench/churn.h: * MallocBench/MallocBench/facebook.cpp: (benchmark_facebook): * MallocBench/MallocBench/facebook.h: * MallocBench/MallocBench/flickr.cpp: (benchmark_flickr): (benchmark_flickr_memory_warning): * MallocBench/MallocBench/flickr.h: * MallocBench/MallocBench/fragment.cpp: (validate): (benchmark_fragment): (benchmark_fragment_iterate): * MallocBench/MallocBench/fragment.h: * MallocBench/MallocBench/list.cpp: (benchmark_list_allocate): (benchmark_list_traverse): * MallocBench/MallocBench/list.h: * MallocBench/MallocBench/main.cpp: (main): * MallocBench/MallocBench/medium.cpp: (benchmark_medium): * MallocBench/MallocBench/medium.h: * MallocBench/MallocBench/memalign.cpp: (test): (benchmark_memalign): * MallocBench/MallocBench/memalign.h: * MallocBench/MallocBench/message.cpp: (benchmark_message_one): (benchmark_message_many): * MallocBench/MallocBench/message.h: * MallocBench/MallocBench/nimlang.cpp: Added. (benchmark_nimlang): * MallocBench/MallocBench/nimlang.h: Added. * MallocBench/MallocBench/nimlang.ops: Added. * MallocBench/MallocBench/realloc.cpp: (benchmark_realloc): * MallocBench/MallocBench/realloc.h: * MallocBench/MallocBench/reddit.cpp: (benchmark_reddit): (benchmark_reddit_memory_warning): * MallocBench/MallocBench/reddit.h: * MallocBench/MallocBench/stress.cpp: (deallocate): (benchmark_stress): * MallocBench/MallocBench/stress.h: * MallocBench/MallocBench/stress_aligned.cpp: (benchmark_stress_aligned): * MallocBench/MallocBench/stress_aligned.h: * MallocBench/MallocBench/theverge.cpp: (benchmark_theverge): (benchmark_theverge_memory_warning): * MallocBench/MallocBench/theverge.h: * MallocBench/MallocBench/tree.cpp: (benchmark_tree_allocate): (benchmark_tree_traverse): (benchmark_tree_churn): * MallocBench/MallocBench/tree.h: * MallocBench/run-malloc-benchmarks: Canonical link: https://commits.webkit.org/172661@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196955 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-22 22:02:24 +00:00
if (commandLine.isParallel())
Let's benchmark malloc https://bugs.webkit.org/show_bug.cgi?id=131118 Reviewed by Mark Hahnenberg. I want to replace fastMalloc with something faster (fasterMalloc?). I wrote these benchmarks to test / drive development. * MallocBench: Added. * MallocBench/MallocBench: Added. * MallocBench/MallocBench.xcodeproj: Added. * MallocBench/MallocBench.xcodeproj/project.pbxproj: Added. * MallocBench/MallocBench/Benchmark.cpp: Added. (allocateHeap): (deallocateHeap): (Benchmark::Benchmark): (Benchmark::printBenchmarks): (Benchmark::runOnce): (Benchmark::run): (Benchmark::printReport): (Benchmark::currentTimeMS): (Benchmark::currentMemoryBytes): * MallocBench/MallocBench/Benchmark.h: Added. (Benchmark::Memory::Memory): (Benchmark::Memory::operator-): (Benchmark::isValid): * MallocBench/MallocBench/CPUCount.cpp: Added. (cpuCount): * MallocBench/MallocBench/CPUCount.h: Added. * MallocBench/MallocBench/CommandLine.cpp: Added. (CommandLine::printUsage): * MallocBench/MallocBench/CommandLine.h: Added. (CommandLine::isValid): (CommandLine::benchmarkName): (CommandLine::isParallel): (CommandLine::heapSize): (CommandLine::measureHeap): * MallocBench/MallocBench/Interpreter.cpp: Added. (Interpreter::Interpreter): (Interpreter::~Interpreter): (Interpreter::run): * MallocBench/MallocBench/Interpreter.h: Added. * MallocBench/MallocBench/balloon.cpp: Added. (benchmark_balloon): * MallocBench/MallocBench/balloon.h: Added. * MallocBench/MallocBench/big.cpp: Added. (benchmark_big): * MallocBench/MallocBench/big.h: Added. * MallocBench/MallocBench/churn.cpp: Added. (HeapDouble::operator new): (HeapDouble::operator delete): (HeapDouble::HeapDouble): (HeapDouble::operator+=): (benchmark_churn): * MallocBench/MallocBench/churn.h: Added. * MallocBench/MallocBench/crash.ops: Added. * MallocBench/MallocBench/facebook.cpp: Added. (benchmark_facebook): * MallocBench/MallocBench/facebook.h: Added. * MallocBench/MallocBench/facebook.ops: Added. * MallocBench/MallocBench/fragment.cpp: Added. (validate): (benchmark_fragment): (benchmark_fragment_iterate): * MallocBench/MallocBench/fragment.h: Added. * MallocBench/MallocBench/list.cpp: Added. (benchmark_list_allocate): (benchmark_list_traverse): * MallocBench/MallocBench/list.h: Added. * MallocBench/MallocBench/main.cpp: Added. (main): * MallocBench/MallocBench/mbmalloc.cpp: Added. * MallocBench/MallocBench/mbmalloc.h: Added. * MallocBench/MallocBench/medium.cpp: Added. (benchmark_medium): * MallocBench/MallocBench/medium.h: Added. * MallocBench/MallocBench/message.cpp: Added. (benchmark_message_one): (benchmark_message_many): * MallocBench/MallocBench/message.h: Added. * MallocBench/MallocBench/realloc.cpp: Added. (benchmark_realloc): * MallocBench/MallocBench/realloc.h: Added. * MallocBench/MallocBench/tree.cpp: Added. (benchmark_tree_allocate): (benchmark_tree_traverse): (benchmark_tree_churn): * MallocBench/MallocBench/tree.h: Added. * MallocBench/run-malloc-benchmarks: Added. Canonical link: https://commits.webkit.org/149171@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-02 21:38:49 +00:00
vmSize /= cpuCount();
size_t objectCount = vmSize / objectSizeMin;
srandom(0); // For consistency between runs.
for (size_t i = 0; i < times; ++i) {
Object* objects = (Object*)mbmalloc(objectCount * sizeof(Object));
bzero(objects, objectCount * sizeof(Object));
for (size_t i = 0, remaining = vmSize; remaining > objectSizeMin; ++i) {
size_t size = min<size_t>(remaining, max<size_t>(objectSizeMin, random() % objectSizeMax));
Let's benchmark malloc https://bugs.webkit.org/show_bug.cgi?id=131118 Reviewed by Mark Hahnenberg. I want to replace fastMalloc with something faster (fasterMalloc?). I wrote these benchmarks to test / drive development. * MallocBench: Added. * MallocBench/MallocBench: Added. * MallocBench/MallocBench.xcodeproj: Added. * MallocBench/MallocBench.xcodeproj/project.pbxproj: Added. * MallocBench/MallocBench/Benchmark.cpp: Added. (allocateHeap): (deallocateHeap): (Benchmark::Benchmark): (Benchmark::printBenchmarks): (Benchmark::runOnce): (Benchmark::run): (Benchmark::printReport): (Benchmark::currentTimeMS): (Benchmark::currentMemoryBytes): * MallocBench/MallocBench/Benchmark.h: Added. (Benchmark::Memory::Memory): (Benchmark::Memory::operator-): (Benchmark::isValid): * MallocBench/MallocBench/CPUCount.cpp: Added. (cpuCount): * MallocBench/MallocBench/CPUCount.h: Added. * MallocBench/MallocBench/CommandLine.cpp: Added. (CommandLine::printUsage): * MallocBench/MallocBench/CommandLine.h: Added. (CommandLine::isValid): (CommandLine::benchmarkName): (CommandLine::isParallel): (CommandLine::heapSize): (CommandLine::measureHeap): * MallocBench/MallocBench/Interpreter.cpp: Added. (Interpreter::Interpreter): (Interpreter::~Interpreter): (Interpreter::run): * MallocBench/MallocBench/Interpreter.h: Added. * MallocBench/MallocBench/balloon.cpp: Added. (benchmark_balloon): * MallocBench/MallocBench/balloon.h: Added. * MallocBench/MallocBench/big.cpp: Added. (benchmark_big): * MallocBench/MallocBench/big.h: Added. * MallocBench/MallocBench/churn.cpp: Added. (HeapDouble::operator new): (HeapDouble::operator delete): (HeapDouble::HeapDouble): (HeapDouble::operator+=): (benchmark_churn): * MallocBench/MallocBench/churn.h: Added. * MallocBench/MallocBench/crash.ops: Added. * MallocBench/MallocBench/facebook.cpp: Added. (benchmark_facebook): * MallocBench/MallocBench/facebook.h: Added. * MallocBench/MallocBench/facebook.ops: Added. * MallocBench/MallocBench/fragment.cpp: Added. (validate): (benchmark_fragment): (benchmark_fragment_iterate): * MallocBench/MallocBench/fragment.h: Added. * MallocBench/MallocBench/list.cpp: Added. (benchmark_list_allocate): (benchmark_list_traverse): * MallocBench/MallocBench/list.h: Added. * MallocBench/MallocBench/main.cpp: Added. (main): * MallocBench/MallocBench/mbmalloc.cpp: Added. * MallocBench/MallocBench/mbmalloc.h: Added. * MallocBench/MallocBench/medium.cpp: Added. (benchmark_medium): * MallocBench/MallocBench/medium.h: Added. * MallocBench/MallocBench/message.cpp: Added. (benchmark_message_one): (benchmark_message_many): * MallocBench/MallocBench/message.h: Added. * MallocBench/MallocBench/realloc.cpp: Added. (benchmark_realloc): * MallocBench/MallocBench/realloc.h: Added. * MallocBench/MallocBench/tree.cpp: Added. (benchmark_tree_allocate): (benchmark_tree_traverse): (benchmark_tree_churn): * MallocBench/MallocBench/tree.h: Added. * MallocBench/run-malloc-benchmarks: Added. Canonical link: https://commits.webkit.org/149171@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-04-02 21:38:49 +00:00
objects[i] = { (double*)mbmalloc(size), size };
bzero(objects[i].p, size);
remaining -= size;
}
for (size_t i = 0; i < objectCount && objects[i].p; ++i)
mbfree(objects[i].p, objects[i].size);
mbfree(objects, objectCount * sizeof(Object));
}
}