2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
12 // Used to prevent the compiler from optimizing away the whole loop.
13 volatile uint32_t blackhole = 0;
15 // Not a great random number generator, but it's very fast.
16 // The code we're measuring is quite fast, so low overhead is essential.
17 static uint32_t lcg_rand(uint32_t* seed) {
23 struct Sk4fBytesRoundtripBench : public Benchmark {
24 Sk4fBytesRoundtripBench() {}
26 const char* onGetName() override { return "Sk4f_roundtrip"; }
27 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
29 void onDraw(int loops, SkCanvas* canvas) override {
30 // Unlike blackhole, junk can and probably will be a register.
33 for (int i = 0; i < loops; i++) {
34 uint32_t color = lcg_rand(&seed),
36 auto f = Sk4f::FromBytes((const uint8_t*)&color);
37 f.toBytes((uint8_t*)&back);
43 DEF_BENCH(return new Sk4fBytesRoundtripBench;)
45 struct Sk4fGradientBench : public Benchmark {
46 const char* onGetName() override { return "Sk4f_gradient"; }
47 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
49 SkPMColor fDevice[100];
50 void onDraw(int loops, SkCanvas*) override {
57 dcdx4(dcdx+dcdx+dcdx+dcdx);
59 for (int n = 0; n < loops; n++) {
60 Sk4f a = c0 + dc*fx + Sk4f(0.5f), // add an extra 0.5f to get rounding for free.
64 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) {
65 Sk4f::ToBytes((uint8_t*)(fDevice+i), a, b, c, d);
74 DEF_BENCH(return new Sk4fGradientBench;)