aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/MathBench.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bench/MathBench.cpp')
-rw-r--r--bench/MathBench.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/bench/MathBench.cpp b/bench/MathBench.cpp
index 77ba2f04be..877d42663c 100644
--- a/bench/MathBench.cpp
+++ b/bench/MathBench.cpp
@@ -607,3 +607,29 @@ DEF_BENCH( return new CLZBench(true); )
DEF_BENCH( return new NormalizeBench(); )
DEF_BENCH( return new FixedMathBench(); )
+
+
+struct FloatToIntBench : public Benchmark {
+ enum { N = 1000000 };
+ float fFloats[N];
+ int fInts [N];
+
+ const char* onGetName() override { return "float_to_int"; }
+ bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
+
+ void onDelayedSetup() override {
+ const auto f32 = 4294967296.0f;
+ for (int i = 0; i < N; ++i) {
+ fFloats[i] = -f32 + i*(2*f32/N);
+ }
+ }
+
+ void onDraw(int loops, SkCanvas*) override {
+ while (loops --> 0) {
+ for (int i = 0; i < N; i++) {
+ fInts[i] = SkFloatToIntFloor(fFloats[i]);
+ }
+ }
+ }
+};
+DEF_BENCH( return new FloatToIntBench; )