Skip to content

Commit

Permalink
Remove tests that were actually benchmarks.
Browse files Browse the repository at this point in the history
This allows S2Testing::GetCpuTime and base::CPUUsage() to be removed.
  • Loading branch information
jmr committed Jun 5, 2018
1 parent baf401e commit cdd342f
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 275 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -74,7 +74,6 @@ include_directories(src)
add_library(s2
src/s2/base/stringprintf.cc
src/s2/base/strtoint.cc
src/s2/base/sysinfo.cc
src/s2/encoded_s2cell_id_vector.cc
src/s2/encoded_s2point_vector.cc
src/s2/encoded_s2shape_index.cc
Expand Down
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -18,7 +18,6 @@ S2 documentation can be found on [s2geometry.io](http://s2geometry.io).

## Requirements for End Users

* A POSIX system (for getrusage).
* [CMake](http://www.cmake.org/)
* A C++ compiler with C++11 support, such as [g++](https://gcc.gnu.org/)
\>= 4.7.
Expand Down
29 changes: 0 additions & 29 deletions src/s2/base/sysinfo.cc

This file was deleted.

51 changes: 0 additions & 51 deletions src/s2/base/sysinfo.h

This file was deleted.

65 changes: 0 additions & 65 deletions src/s2/s1angle_test.cc
Expand Up @@ -17,17 +17,12 @@

#include "s2/s1angle.h"

#include "s2/base/commandlineflags.h"
#include "s2/third_party/absl/base/integral_types.h"
#include "s2/base/logging.h"
#include <gtest/gtest.h>
#include "s2/s2latlng.h"
#include "s2/s2testing.h"

DEFINE_int32(iters,
(google::DEBUG_MODE ? 100 : 1000) * (1000 * 1000),
"Run timing tests with this many iterations");

TEST(S1Angle, DefaultConstructor) {
// Check that the default constructor returns an angle of 0.
S1Angle a;
Expand Down Expand Up @@ -142,66 +137,6 @@ TEST(S1Angle, TestFormatting) {
EXPECT_EQ("180.0000000", ss.str());
}

TEST(S1Angle, TestPerformance) {
// Verify that the conversion to E5/E6/E7 is not much slower than the
// conversion from E5/E6/E7. (Float-to-integer conversions can be quite
// slow on some platforms.) We only check the times for E6; the times for
// E5/E7 should be similar.

// To reduce the impact of loop overhead, we do kOpsPerLoop ops per loop.
static const int kOpsPerLoop = 8;

// Time conversion from E6 to radians.
double rad_sum = 0;
const double from_e6_start = S2Testing::GetCpuTime();
for (int i = FLAGS_iters; i > 0; i -= kOpsPerLoop) {
// We structure both loops so that all the conversions can be done in
// parallel. Otherwise on some platforms the optimizer happens to do a
// much better job of parallelizing one loop than the other.
double r0 = S1Angle::E6(i-0).radians();
double r1 = S1Angle::E6(i-1).radians();
double r2 = S1Angle::E6(i-2).radians();
double r3 = S1Angle::E6(i-3).radians();
double r4 = S1Angle::E6(i-4).radians();
double r5 = S1Angle::E6(i-5).radians();
double r6 = S1Angle::E6(i-6).radians();
double r7 = S1Angle::E6(i-7).radians();
rad_sum += ((r0 + r1) + (r2 + r3)) + ((r4 + r5) + (r6 + r7));
}
const double from_e6_time = S2Testing::GetCpuTime() - from_e6_start;
EXPECT_NE(rad_sum, 0); // Don't let the sum get optimized away.
S2_LOG(INFO) << "From E6: "
<< (FLAGS_iters / from_e6_time)
<< " values per second";

// Time conversion from radians to E6.
const double delta = (2 * M_PI) / (FLAGS_iters - 1);
double angle = -M_PI;
int64 e6_sum = 0;
const double to_e6_start = S2Testing::GetCpuTime();
for (int i = FLAGS_iters; i > 0; i -= kOpsPerLoop) {
int64 r0 = S1Angle::Radians(angle).e6(); angle += delta;
int64 r1 = S1Angle::Radians(angle).e6(); angle += delta;
int64 r2 = S1Angle::Radians(angle).e6(); angle += delta;
int64 r3 = S1Angle::Radians(angle).e6(); angle += delta;
int64 r4 = S1Angle::Radians(angle).e6(); angle += delta;
int64 r5 = S1Angle::Radians(angle).e6(); angle += delta;
int64 r6 = S1Angle::Radians(angle).e6(); angle += delta;
int64 r7 = S1Angle::Radians(angle).e6(); angle += delta;
e6_sum += ((r0 + r1) + (r2 + r3)) + ((r4 + r5) + (r6 + r7));
}
const double to_e6_time = S2Testing::GetCpuTime() - to_e6_start;
EXPECT_NE(e6_sum + angle, 0); // Don't let them get optimized away.
S2_LOG(INFO) << " To E6: "
<< (FLAGS_iters / to_e6_time)
<< " values per second";

// Make sure that the To/From E6 times are not much different.
// The difference factor slightly less than 2 on an x86_64.
EXPECT_LE(from_e6_time / to_e6_time, 3);
EXPECT_LE(to_e6_time / from_e6_time, 3);
}

// The current implementation guarantees exact conversions between
// Degrees() and E6() when the Degrees() argument is an integer.
TEST(S1Angle, DegreesVsE6) {
Expand Down
86 changes: 0 additions & 86 deletions src/s2/s2cell_id_test.cc
Expand Up @@ -25,7 +25,6 @@
#include <unordered_map>
#include <vector>

#include "s2/base/commandlineflags.h"
#include "s2/base/logging.h"
#include "s2/third_party/absl/base/macros.h"
#include <gtest/gtest.h>
Expand All @@ -43,9 +42,6 @@ using std::min;
using std::unordered_map;
using std::vector;

DEFINE_int32(iters, 20000000,
"Number of iterations for timing tests with optimized build");

static S2CellId GetCellId(double lat_degrees, double lng_degrees) {
S2CellId id(S2LatLng::FromDegrees(lat_degrees, lng_degrees));
S2_LOG(INFO) << std::hex << id.id();
Expand Down Expand Up @@ -634,85 +630,3 @@ TEST(S2CellId, OutputOperator) {
EXPECT_EQ("5/31200", s.str());
}

TEST(S2CellId, ToPointBenchmark) {
// This "test" is really a benchmark, so skip it unless we're optimized.
if (google::DEBUG_MODE) return;

// Test speed of conversions from points to leaf cells.
double control_start = S2Testing::GetCpuTime();
S2CellId begin = S2CellId::Begin(S2CellId::kMaxLevel);
S2CellId end = S2CellId::End(S2CellId::kMaxLevel);
uint64 delta = (end.id() - begin.id()) / FLAGS_iters;
delta &= ~1ULL; // Make sure all ids are leaf cells.

S2CellId id = begin;
double sum = 0;
for (int i = FLAGS_iters; i > 0; --i) {
sum += static_cast<double>(id.id());
id = S2CellId(id.id() + delta);
}
double control_time = S2Testing::GetCpuTime() - control_start;
printf("\tControl: %8.3f usecs\n", 1e6 * control_time / FLAGS_iters);
EXPECT_NE(sum, 0); // Don't let the loop get optimized away.

double test_start = S2Testing::GetCpuTime();
sum = 0;
id = begin;
for (int i = FLAGS_iters; i > 0; --i) {
sum += id.ToPointRaw()[0];
id = S2CellId(id.id() + delta);
}
double test_time = S2Testing::GetCpuTime() - test_start - control_time;
printf("\tToPointRaw: %8.3f usecs\n", 1e6 * test_time / FLAGS_iters);
EXPECT_NE(sum, 0); // Don't let the loop get optimized away.

test_start = S2Testing::GetCpuTime();
sum = 0;
id = begin;
for (int i = FLAGS_iters; i > 0; --i) {
sum += id.ToPoint()[0];
id = S2CellId(id.id() + delta);
}
test_time = S2Testing::GetCpuTime() - test_start - control_time;
printf("\tToPoint: %8.3f usecs\n", 1e6 * test_time / FLAGS_iters);
EXPECT_NE(sum, 0); // Don't let the loop get optimized away.
}

TEST(S2CellId, FromPointBenchmark) {
// This "test" is really a benchmark, so skip it unless we're optimized.
if (google::DEBUG_MODE) return;

// The sample points follow a spiral curve that completes one revolution
// around the z-axis every 1/dt samples. The z-coordinate increases
// from -4 to +4 over FLAGS_iters samples.

S2Point start(1, 0, -4);
double dz = (-2 * start.z()) / FLAGS_iters;
double dt = 1.37482937133e-4;

// Test speed of conversions from leaf cells to points.
double control_start = S2Testing::GetCpuTime();
uint64 isum = 0;
S2Point p = start;
for (int i = FLAGS_iters; i > 0; --i) {
// Cheap rotation around the z-axis (spirals inward slightly
// each revolution).
p += S2Point(-dt * p.y(), dt * p.x(), dz);
isum += MathUtil::FastIntRound(p[0] + p[1] + p[2]);
}
double control_time = S2Testing::GetCpuTime() - control_start;
printf("\tControl: %8.3f usecs\n", 1e6 * control_time / FLAGS_iters);
EXPECT_NE(isum, 0); // Don't let the loop get optimized away.

double test_start = S2Testing::GetCpuTime();
isum = 0;
p = start;
for (int i = FLAGS_iters; i > 0; --i) {
p += S2Point(-dt * p.y(), dt * p.x(), dz);
isum += S2CellId(p).id();
}
double test_time = S2Testing::GetCpuTime() - test_start - control_time;
printf("\tFromPoint: %8.3f usecs\n", 1e6 * test_time / FLAGS_iters);
EXPECT_NE(isum, 0); // Don't let the loop get optimized away.
}

33 changes: 1 addition & 32 deletions src/s2/s2cell_test.cc
Expand Up @@ -58,6 +58,7 @@ using std::map;
using std::max;
using std::min;
using std::pair;
using std::pow;
using std::vector;

TEST(S2Cell, TestFaces) {
Expand Down Expand Up @@ -399,38 +400,6 @@ TEST(S2Cell, TestSubdivide) {
}
}

static const int kMaxLevel = google::DEBUG_MODE ? 6 : 11;

static void ExpandChildren1(const S2Cell& cell) {
S2Cell children[4];
S2_CHECK(cell.Subdivide(children));
if (children[0].level() < kMaxLevel) {
for (int pos = 0; pos < 4; ++pos) {
ExpandChildren1(children[pos]);
}
}
}

static void ExpandChildren2(const S2Cell& cell) {
S2CellId id = cell.id().child_begin();
for (int pos = 0; pos < 4; ++pos, id = id.next()) {
S2Cell child(id);
if (child.level() < kMaxLevel) ExpandChildren2(child);
}
}

TEST(S2Cell, TestPerformance) {
double subdivide_start = S2Testing::GetCpuTime();
ExpandChildren1(S2Cell::FromFace(0));
double subdivide_time = S2Testing::GetCpuTime() - subdivide_start;
fprintf(stderr, "Subdivide: %.3f seconds\n", subdivide_time);

double constructor_start = S2Testing::GetCpuTime();
ExpandChildren2(S2Cell::FromFace(0));
double constructor_time = S2Testing::GetCpuTime() - constructor_start;
fprintf(stderr, "Constructor: %.3f seconds\n", constructor_time);
}

TEST(S2Cell, CellVsLoopRectBound) {
// This test verifies that the S2Cell and S2Loop bounds contain each other
// to within their maximum errors.
Expand Down
7 changes: 0 additions & 7 deletions src/s2/s2testing.cc
Expand Up @@ -28,7 +28,6 @@
#include "s2/base/commandlineflags.h"
#include "s2/third_party/absl/base/integral_types.h"
#include "s2/base/logging.h"
#include "s2/base/sysinfo.h"
#include "s2/strings/serialize.h"
#include "s2/third_party/absl/memory/memory.h"
#include "s2/third_party/absl/strings/str_split.h"
Expand Down Expand Up @@ -318,12 +317,6 @@ void S2Testing::CheckCovering(const S2Region& region,
}
}

double S2Testing::GetCpuTime() {
absl::Duration usage = base::CPUUsage();
S2_CHECK(usage != absl::ZeroDuration()); // Indicates error.
return ToDoubleSeconds(usage);
}

S2Testing::Fractal::Fractal()
: max_level_(-1), min_level_arg_(-1), min_level_(-1),
dimension_(log(4)/log(3)), /* standard Koch curve */
Expand Down
3 changes: 0 additions & 3 deletions src/s2/s2testing.h
Expand Up @@ -234,9 +234,6 @@ class S2Testing {
bool check_tight,
S2CellId id = S2CellId());

// Returns the user time consumed by this process, in seconds.
static double GetCpuTime();

private:
// Contains static methods
S2Testing() = delete;
Expand Down

0 comments on commit cdd342f

Please sign in to comment.