2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2011-06-06 17:55:11 +00:00
|
|
|
#include "SkFloatBits.h"
|
2011-06-06 15:16:31 +00:00
|
|
|
#include "SkRandom.h"
|
2012-05-15 14:14:04 +00:00
|
|
|
#include "SkRect.h"
|
2011-06-06 15:16:31 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ScalarBench : public Benchmark {
|
2011-06-06 15:16:31 +00:00
|
|
|
SkString fName;
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ScalarBench(const char name[]) {
|
2011-06-06 15:16:31 +00:00
|
|
|
fName.printf("scalar_%s", name);
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2011-06-06 15:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void performTest() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int mulLoopCount() const { return 1; }
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2011-06-06 15:16:31 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2011-06-06 15:16:31 +00:00
|
|
|
this->performTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-06-06 15:16:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// having unknown values in our arrays can throw off the timing a lot, perhaps
|
|
|
|
// handling NaN values is a lot slower. Anyway, this guy is just meant to put
|
|
|
|
// reasonable values in our arrays.
|
|
|
|
template <typename T> void init9(T array[9]) {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2011-06-06 15:16:31 +00:00
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
array[i] = rand.nextSScalar1();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FloatComparisonBench : public ScalarBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
FloatComparisonBench() : INHERITED("compare_float") {
|
2011-06-06 15:16:31 +00:00
|
|
|
init9(fArray);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual int mulLoopCount() const { return 4; }
|
|
|
|
virtual void performTest() {
|
2014-06-02 19:41:07 +00:00
|
|
|
// xoring into a volatile prevents the compiler from optimizing these checks away.
|
|
|
|
volatile bool junk = false;
|
|
|
|
junk ^= (fArray[6] != 0.0f || fArray[7] != 0.0f || fArray[8] != 1.0f);
|
|
|
|
junk ^= (fArray[2] != 0.0f || fArray[5] != 0.0f);
|
2011-06-06 15:16:31 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
float fArray[9];
|
|
|
|
typedef ScalarBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ForcedIntComparisonBench : public ScalarBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ForcedIntComparisonBench()
|
|
|
|
: INHERITED("compare_forced_int") {
|
2011-06-06 15:16:31 +00:00
|
|
|
init9(fArray);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual int mulLoopCount() const { return 4; }
|
|
|
|
virtual void performTest() {
|
2014-06-02 19:41:07 +00:00
|
|
|
// xoring into a volatile prevents the compiler from optimizing these checks away.
|
|
|
|
volatile int32_t junk = 0;
|
|
|
|
junk ^= (SkScalarAs2sCompliment(fArray[6]) |
|
|
|
|
SkScalarAs2sCompliment(fArray[7]) |
|
|
|
|
(SkScalarAs2sCompliment(fArray[8]) - kPersp1Int));
|
|
|
|
junk ^= (SkScalarAs2sCompliment(fArray[2]) |
|
|
|
|
SkScalarAs2sCompliment(fArray[5]));
|
2011-06-06 15:16:31 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
static const int32_t kPersp1Int = 0x3f800000;
|
2011-06-06 17:55:11 +00:00
|
|
|
SkScalar fArray[9];
|
2011-06-06 15:16:31 +00:00
|
|
|
typedef ScalarBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-06-13 12:30:35 +00:00
|
|
|
class IsFiniteScalarBench : public ScalarBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
IsFiniteScalarBench() : INHERITED("isfinite") {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-06-13 12:30:35 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_N; ++i) {
|
|
|
|
fArray[i] = rand.nextSScalar1();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
int mulLoopCount() const override { return 1; }
|
|
|
|
void performTest() override {
|
2012-06-13 12:30:35 +00:00
|
|
|
int sum = 0;
|
|
|
|
for (size_t i = 0; i < ARRAY_N; ++i) {
|
|
|
|
// We pass -fArray[i], so the compiler can't cheat and treat the
|
|
|
|
// value as an int (even though we tell it that it is a float)
|
|
|
|
sum += SkScalarIsFinite(-fArray[i]);
|
|
|
|
}
|
|
|
|
// we do this so the compiler won't optimize our loop away...
|
|
|
|
this->doSomething(fArray, sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void doSomething(SkScalar array[], int sum) {}
|
|
|
|
private:
|
|
|
|
enum {
|
|
|
|
ARRAY_N = 64
|
|
|
|
};
|
|
|
|
SkScalar fArray[ARRAY_N];
|
|
|
|
|
|
|
|
typedef ScalarBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-05-15 14:14:04 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RectBoundsBench : public Benchmark {
|
2012-05-15 14:14:04 +00:00
|
|
|
enum {
|
|
|
|
PTS = 100,
|
|
|
|
};
|
|
|
|
SkPoint fPts[PTS];
|
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
RectBoundsBench() {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-05-15 14:14:04 +00:00
|
|
|
for (int i = 0; i < PTS; ++i) {
|
|
|
|
fPts[i].fX = rand.nextSScalar1();
|
|
|
|
fPts[i].fY = rand.nextSScalar1();
|
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-15 14:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-15 14:14:04 +00:00
|
|
|
return "rect_bounds";
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2012-05-15 14:14:04 +00:00
|
|
|
SkRect r;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2015-03-25 21:30:49 +00:00
|
|
|
for (int i = 0; i < 1000; ++i) {
|
|
|
|
r.set(fPts, PTS);
|
|
|
|
}
|
2012-05-15 14:14:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-15 14:14:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new FloatComparisonBench(); )
|
|
|
|
DEF_BENCH( return new ForcedIntComparisonBench(); )
|
|
|
|
DEF_BENCH( return new RectBoundsBench(); )
|
|
|
|
DEF_BENCH( return new IsFiniteScalarBench(); )
|