Skip to content

Commit

Permalink
Timer update (#856)
Browse files Browse the repository at this point in the history
Faster macos timer
Faster linux timer (hopefully works on emscripten)

I confirmed these timers are fast

Updated M2 MacOS benchmarks
Updated N100 Linux benchmarks
  • Loading branch information
erincatto authored Dec 13, 2024
1 parent d1581fb commit f0763ac
Show file tree
Hide file tree
Showing 41 changed files with 203 additions and 387 deletions.
8 changes: 4 additions & 4 deletions benchmark/m2air_neon/joint_grid.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,515.583
2,968.592
3,1393.95
4,1652.07
1,214.889
2,344.308
3,499.192
4,589.811
8 changes: 4 additions & 4 deletions benchmark/m2air_neon/large_pyramid.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,327.475
2,606.037
3,843.779
4,1057.89
1,326.445
2,594.514
3,826.976
4,1043.61
8 changes: 4 additions & 4 deletions benchmark/m2air_neon/many_pyramids.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,85.4238
2,159.788
3,219.475
4,261.439
1,85.882
2,160.755
3,220.359
4,266.172
5 changes: 5 additions & 0 deletions benchmark/m2air_neon/rain.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
threads,fps
1,152.46
2,253.474
3,326.158
4,396.199
8 changes: 4 additions & 4 deletions benchmark/m2air_neon/smash.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,166.289
2,262.228
3,329.267
4,393.513
1,193.98
2,307.236
3,386.559
4,459.442
5 changes: 5 additions & 0 deletions benchmark/m2air_neon/spinner.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
threads,fps
1,312.26
2,493.611
3,639.152
4,780.522
8 changes: 4 additions & 4 deletions benchmark/m2air_neon/tumbler.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,351.845
2,549.496
3,674.889
4,801.015
1,431.639
2,671.981
3,818.123
4,993.461
8 changes: 4 additions & 4 deletions benchmark/n100_avx2/joint_grid.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,115.85
2,209.251
3,266.537
4,319.147
1,75.178
2,123.214
3,158.983
4,182.112
8 changes: 4 additions & 4 deletions benchmark/n100_avx2/large_pyramid.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,133.69
2,239.395
3,312.458
4,360.458
1,132.297
2,234.621
3,308.883
4,355.701
8 changes: 4 additions & 4 deletions benchmark/n100_avx2/many_pyramids.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,32.0345
2,56.8865
3,71.4046
4,76.2903
1,32.0528
2,56.6901
3,71.2562
4,77.5141
5 changes: 5 additions & 0 deletions benchmark/n100_avx2/rain.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
threads,fps
1,71.7432
2,117.863
3,141.721
4,161.414
8 changes: 4 additions & 4 deletions benchmark/n100_avx2/smash.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,73.9639
2,115.759
3,138.925
4,157.394
1,88.4488
2,135.265
3,162.135
4,184.08
5 changes: 5 additions & 0 deletions benchmark/n100_avx2/spinner.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
threads,fps
1,159.879
2,261.516
3,308.75
4,360.254
8 changes: 4 additions & 4 deletions benchmark/n100_avx2/tumbler.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,163.663
2,261.691
3,317.057
4,362.4
1,205.268
2,320.216
3,389.513
4,449.153
8 changes: 4 additions & 4 deletions benchmark/n100_sse2/joint_grid.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,119.293
2,213.357
3,268.455
4,321.339
1,75.5947
2,123.228
3,160.379
4,181.545
8 changes: 4 additions & 4 deletions benchmark/n100_sse2/large_pyramid.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,128.152
2,229.067
3,302.297
4,348.367
1,127.236
2,226.291
3,297.628
4,345.526
8 changes: 4 additions & 4 deletions benchmark/n100_sse2/many_pyramids.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,30.9601
2,55.0378
3,69.5563
4,77.3663
1,30.8828
2,55.0462
3,69.5406
4,77.7339
5 changes: 5 additions & 0 deletions benchmark/n100_sse2/rain.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
threads,fps
1,72.2901
2,118.753
3,142.61
4,162.35
8 changes: 4 additions & 4 deletions benchmark/n100_sse2/smash.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,73.2282
2,114.239
3,137.388
4,156.341
1,86.2381
2,132.306
3,160.725
4,181.842
5 changes: 5 additions & 0 deletions benchmark/n100_sse2/spinner.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
threads,fps
1,156.855
2,258.638
3,303.717
4,358.492
8 changes: 4 additions & 4 deletions benchmark/n100_sse2/tumbler.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threads,fps
1,161.228
2,257.781
3,311.219
4,356.481
1,199.492
2,313.012
3,381.983
4,441.825
8 changes: 5 additions & 3 deletions include/box2d/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ typedef struct b2Timer
{
#if defined( _WIN32 )
int64_t start;
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __EMSCRIPTEN__ )
unsigned long long start_sec;
unsigned long long start_usec;
#elif defined( __linux__ ) || defined( __EMSCRIPTEN__ )
int64_t tv_sec;
int64_t tv_nsec;
#elif defined( __APPLE__ )
uint64_t start;
#else
int32_t dummy;
#endif
Expand Down
28 changes: 10 additions & 18 deletions include/box2d/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct b2Hull b2Hull;

/// The maximum number of vertices on a convex polygon. Changing this affects performance even if you
/// don't use more vertices.
#define b2_maxPolygonVertices 8
#define B2_MAX_POLYGON_VERTICES 8

/// Low level ray cast input data
typedef struct b2RayCastInput
Expand All @@ -42,7 +42,7 @@ typedef struct b2RayCastInput
typedef struct b2ShapeCastInput
{
/// A point cloud to cast
b2Vec2 points[b2_maxPolygonVertices];
b2Vec2 points[B2_MAX_POLYGON_VERTICES];

/// The number of points
int32_t count;
Expand Down Expand Up @@ -115,17 +115,17 @@ typedef struct b2Capsule

/// A solid convex polygon. It is assumed that the interior of the polygon is to
/// the left of each edge.
/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.
/// Polygons have a maximum number of vertices equal to B2_MAX_POLYGON_VERTICES.
/// In most cases you should not need many vertices for a convex polygon.
/// @warning DO NOT fill this out manually, instead use a helper function like
/// b2MakePolygon or b2MakeBox.
typedef struct b2Polygon
{
/// The polygon vertices
b2Vec2 vertices[b2_maxPolygonVertices];
b2Vec2 vertices[B2_MAX_POLYGON_VERTICES];

/// The outward normal vectors of the polygon sides
b2Vec2 normals[b2_maxPolygonVertices];
b2Vec2 normals[B2_MAX_POLYGON_VERTICES];

/// The centroid of the polygon
b2Vec2 centroid;
Expand Down Expand Up @@ -273,7 +273,7 @@ B2_API b2CastOutput b2ShapeCastPolygon( const b2ShapeCastInput* input, const b2P
typedef struct b2Hull
{
/// The final points of the hull
b2Vec2 points[b2_maxPolygonVertices];
b2Vec2 points[B2_MAX_POLYGON_VERTICES];

/// The number of points
int32_t count;
Expand All @@ -284,7 +284,7 @@ typedef struct b2Hull
/// - all points very close together
/// - all points on a line
/// - less than 3 points
/// - more than b2_maxPolygonVertices points
/// - more than B2_MAX_POLYGON_VERTICES points
/// This welds close points and removes collinear points.
/// @warning Do not modify a hull once it has been computed
B2_API b2Hull b2ComputeHull( const b2Vec2* points, int32_t count );
Expand Down Expand Up @@ -333,7 +333,7 @@ B2_API b2SegmentDistanceResult b2SegmentDistance( b2Vec2 p1, b2Vec2 q1, b2Vec2 p
typedef struct b2DistanceProxy
{
/// The point cloud
b2Vec2 points[b2_maxPolygonVertices];
b2Vec2 points[B2_MAX_POLYGON_VERTICES];

/// The number of points
int32_t count;
Expand Down Expand Up @@ -601,21 +601,13 @@ B2_API b2Manifold b2CollideChainSegmentAndPolygon( const b2ChainSegment* segment
* A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt.
* A dynamic tree arranges data in a binary tree to accelerate
* queries such as AABB queries and ray casts. Leaf nodes are proxies
* with an AABB. These are used to hold a user collision object, such as a reference to a b2Shape.
* with an AABB. These are used to hold a user collision object.
* Nodes are pooled and relocatable, so I use node indices rather than pointers.
* The dynamic tree is made available for advanced users that would like to use it to organize
* spatial game data besides rigid bodies.
*
* @note This is an advanced feature and normally not used by applications directly.
* @{
*/

/// The default category bit for a tree proxy. Used for collision filtering.
#define b2_defaultCategoryBits ( 1 )

/// Convenience mask bits to use when you don't need collision filtering and just want all results.
#define b2_defaultMaskBits ( UINT64_MAX )

/// A node in the dynamic tree. This is private data placed here for performance reasons.
typedef struct b2TreeNode
{
Expand Down Expand Up @@ -653,7 +645,7 @@ typedef struct b2TreeNode
/// The dynamic tree structure. This should be considered private data.
/// It is placed here for performance reasons.
typedef struct b2DynamicTree
{
{
/// The tree nodes
b2TreeNode* nodes;

Expand Down
2 changes: 1 addition & 1 deletion samples/sample_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ class BenchmarkCast : public Sample
int nodeVisits = 0;
int leafVisits = 0;
float ms = 0.0f;
int sampleCount = m_origins.size();
int sampleCount = (int)m_origins.size();

if ( m_queryType == e_rayCast )
{
Expand Down
16 changes: 8 additions & 8 deletions samples/sample_collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class DynamicTree : public Sample
p->fatBox.lowerBound = b2Sub( p->box.lowerBound, aabbMargin );
p->fatBox.upperBound = b2Add( p->box.upperBound, aabbMargin );

p->proxyId = b2DynamicTree_CreateProxy( &m_tree, p->fatBox, b2_defaultCategoryBits, m_proxyCount );
p->proxyId = b2DynamicTree_CreateProxy( &m_tree, p->fatBox, B2_DEFAULT_CATEGORY_BITS, m_proxyCount );
p->rayStamp = -1;
p->queryStamp = -1;
p->moved = false;
Expand Down Expand Up @@ -682,7 +682,7 @@ class DynamicTree : public Sample
if ( m_queryDrag )
{
b2AABB box = { b2Min( m_startPoint, m_endPoint ), b2Max( m_startPoint, m_endPoint ) };
b2DynamicTree_Query( &m_tree, box, b2_defaultMaskBits, QueryCallback, this );
b2DynamicTree_Query( &m_tree, box, B2_DEFAULT_MASK_BITS, QueryCallback, this );

g_draw.DrawAABB( box, b2_colorWhite );
}
Expand All @@ -693,7 +693,7 @@ class DynamicTree : public Sample
if ( m_rayDrag )
{
b2RayCastInput input = { m_startPoint, b2Sub( m_endPoint, m_startPoint ), 1.0f };
b2TreeStats result = b2DynamicTree_RayCast( &m_tree, &input, b2_defaultMaskBits, RayCallback, this );
b2TreeStats result = b2DynamicTree_RayCast( &m_tree, &input, B2_DEFAULT_MASK_BITS, RayCallback, this );

g_draw.DrawSegment( m_startPoint, m_endPoint, b2_colorWhite );
g_draw.DrawPoint( m_startPoint, 5.0f, b2_colorGreen );
Expand Down Expand Up @@ -2162,7 +2162,7 @@ class OverlapWorld : public Sample
{
b2World_OverlapPolygon( m_worldId, &m_queryBox, transform, b2DefaultQueryFilter(), OverlapWorld::OverlapResultFcn,
this );
b2Vec2 points[b2_maxPolygonVertices] = { 0 };
b2Vec2 points[B2_MAX_POLYGON_VERTICES] = { 0 };
for ( int i = 0; i < m_queryBox.count; ++i )
{
points[i] = b2TransformPoint( transform, m_queryBox.vertices[i] );
Expand Down Expand Up @@ -3316,7 +3316,7 @@ class ShapeCast : public Sample
output.iterations, output.fraction, distanceOutput.distance );
m_textLine += m_textIncrement;

b2Vec2 vertices[b2_maxPolygonVertices];
b2Vec2 vertices[B2_MAX_POLYGON_VERTICES];

for ( int i = 0; i < m_countA; ++i )
{
Expand Down Expand Up @@ -3392,11 +3392,11 @@ class ShapeCast : public Sample
g_draw.DrawSegment( m_transformB.p, b2Add( m_transformB.p, m_translationB ), b2_colorGray );
}

b2Vec2 m_vAs[b2_maxPolygonVertices];
b2Vec2 m_vAs[B2_MAX_POLYGON_VERTICES];
int m_countA;
float m_radiusA;

b2Vec2 m_vBs[b2_maxPolygonVertices];
b2Vec2 m_vBs[B2_MAX_POLYGON_VERTICES];
int m_countB;
float m_radiusB;

Expand Down Expand Up @@ -3497,7 +3497,7 @@ class TimeOfImpact : public Sample
// b2_toiMaxRootIters);
m_textLine += m_textIncrement;

b2Vec2 vertices[b2_maxPolygonVertices];
b2Vec2 vertices[B2_MAX_POLYGON_VERTICES];

// Draw A
b2Transform transformA = b2GetSweepTransform( &sweepA, 0.0f );
Expand Down
4 changes: 2 additions & 2 deletions samples/sample_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ConvexHull : public Sample
public:
enum
{
e_count = b2_maxPolygonVertices
e_count = B2_MAX_POLYGON_VERTICES
};

explicit ConvexHull( Settings& settings )
Expand Down Expand Up @@ -211,7 +211,7 @@ class ConvexHull : public Sample
return new ConvexHull( settings );
}

b2Vec2 m_points[b2_maxPolygonVertices];
b2Vec2 m_points[B2_MAX_POLYGON_VERTICES];
int32_t m_count;
int32_t m_generation;
bool m_auto;
Expand Down
Loading

0 comments on commit f0763ac

Please sign in to comment.