diff options
author | mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-20 14:31:45 +0000 |
---|---|---|
committer | mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-20 14:31:45 +0000 |
commit | 519f9677a41239808f41a7c13ef1f6e05eb1ed50 (patch) | |
tree | a7a1acf5fc2c9d8c2390c48bc1a604628ff513e5 /bench | |
parent | f91e3d4f54de9976b6538decadd977b19e49eadd (diff) |
Add sk_calloc. Remove SkMemory_stdlib, which seems unused.
I'm seeing basically no difference between malloc + bzero and calloc on my desktop, but on a Galaxy Nexus calloc is never slower, and significantly faster once the allocation size becomes large, both for allocation and for _reading_.
BUG=skia:1662
R=reed@google.com
Review URL: https://codereview.chromium.org/24251008
git-svn-id: http://skia.googlecode.com/svn/trunk@11414 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench')
-rw-r--r-- | bench/MemoryBench.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/bench/MemoryBench.cpp b/bench/MemoryBench.cpp index 6e8e4a8588..418e149f80 100644 --- a/bench/MemoryBench.cpp +++ b/bench/MemoryBench.cpp @@ -52,3 +52,108 @@ private: DEF_BENCH( return new ChunkAllocBench(64); ) DEF_BENCH( return new ChunkAllocBench(8*1024); ) + +static int* calloc(size_t num) { + return (int*)sk_calloc_throw(num*sizeof(int)); +} + +static int* malloc_bzero(size_t num) { + const size_t bytes = num*sizeof(int); + int* ints = (int*)sk_malloc_throw(bytes); + sk_bzero(ints, bytes); + return ints; +} + +class ZerosBench : public SkBenchmark { + size_t fNum; + bool fRead; + bool fWrite; + bool fUseCalloc; + SkString fName; +public: + ZerosBench(size_t num, bool read, bool write, bool useCalloc) + : fNum(num) + , fRead(read) + , fWrite(write) + , fUseCalloc(useCalloc) { + fName.printf("memory_%s", useCalloc ? "calloc" : "malloc_bzero"); + if (read && write) { + fName.appendf("_rw"); + } else if (read) { + fName.appendf("_r"); + } else if (write) { + fName.appendf("_w"); + } + fName.appendf("_"SK_SIZE_T_SPECIFIER, num); + fIsRendering = false; + } + +protected: + virtual const char* onGetName() SK_OVERRIDE { + return fName.c_str(); + } + + virtual void onDraw(SkCanvas*) SK_OVERRIDE { + for (int i = 0; i < this->getLoops(); i++) { + int* zeros = fUseCalloc ? calloc(fNum) : malloc_bzero(fNum); + if (fRead) { + volatile int x = 15; + for (size_t j = 0; j < fNum; j++) { + x ^= zeros[j]; + } + } + if (fWrite) { + for (size_t j = 0; j < fNum; j++) { + zeros[j] = 15; + } + } + sk_free(zeros); + } + } +}; + +// zero count r w useCalloc? +DEF_BENCH(return new ZerosBench(1024*1024, 0, 0, 0)) +DEF_BENCH(return new ZerosBench(1024*1024, 0, 0, 1)) +DEF_BENCH(return new ZerosBench(1024*1024, 0, 1, 0)) +DEF_BENCH(return new ZerosBench(1024*1024, 0, 1, 1)) +DEF_BENCH(return new ZerosBench(1024*1024, 1, 0, 0)) +DEF_BENCH(return new ZerosBench(1024*1024, 1, 0, 1)) +DEF_BENCH(return new ZerosBench(1024*1024, 1, 1, 0)) +DEF_BENCH(return new ZerosBench(1024*1024, 1, 1, 1)) + +DEF_BENCH(return new ZerosBench(256*1024, 0, 0, 0)) +DEF_BENCH(return new ZerosBench(256*1024, 0, 0, 1)) +DEF_BENCH(return new ZerosBench(256*1024, 0, 1, 0)) +DEF_BENCH(return new ZerosBench(256*1024, 0, 1, 1)) +DEF_BENCH(return new ZerosBench(256*1024, 1, 0, 0)) +DEF_BENCH(return new ZerosBench(256*1024, 1, 0, 1)) +DEF_BENCH(return new ZerosBench(256*1024, 1, 1, 0)) +DEF_BENCH(return new ZerosBench(256*1024, 1, 1, 1)) + +DEF_BENCH(return new ZerosBench(4*1024, 0, 0, 0)) +DEF_BENCH(return new ZerosBench(4*1024, 0, 0, 1)) +DEF_BENCH(return new ZerosBench(4*1024, 0, 1, 0)) +DEF_BENCH(return new ZerosBench(4*1024, 0, 1, 1)) +DEF_BENCH(return new ZerosBench(4*1024, 1, 0, 0)) +DEF_BENCH(return new ZerosBench(4*1024, 1, 0, 1)) +DEF_BENCH(return new ZerosBench(4*1024, 1, 1, 0)) +DEF_BENCH(return new ZerosBench(4*1024, 1, 1, 1)) + +DEF_BENCH(return new ZerosBench(300, 0, 0, 0)) +DEF_BENCH(return new ZerosBench(300, 0, 0, 1)) +DEF_BENCH(return new ZerosBench(300, 0, 1, 0)) +DEF_BENCH(return new ZerosBench(300, 0, 1, 1)) +DEF_BENCH(return new ZerosBench(300, 1, 0, 0)) +DEF_BENCH(return new ZerosBench(300, 1, 0, 1)) +DEF_BENCH(return new ZerosBench(300, 1, 1, 0)) +DEF_BENCH(return new ZerosBench(300, 1, 1, 1)) + +DEF_BENCH(return new ZerosBench(4, 0, 0, 0)) +DEF_BENCH(return new ZerosBench(4, 0, 0, 1)) +DEF_BENCH(return new ZerosBench(4, 0, 1, 0)) +DEF_BENCH(return new ZerosBench(4, 0, 1, 1)) +DEF_BENCH(return new ZerosBench(4, 1, 0, 0)) +DEF_BENCH(return new ZerosBench(4, 1, 0, 1)) +DEF_BENCH(return new ZerosBench(4, 1, 1, 0)) +DEF_BENCH(return new ZerosBench(4, 1, 1, 1)) |