This repository contains performance benchmarks comparing several Rust Entity-Component-System (ECS) libraries using Criterion. We evaluate common operations across Bevy ECS, Hecs, Flecs ECS, Legion, and Specs to understand their relative strengths and trade-offs.
The five benchmark scenarios are:
- Spawn – measuring raw entity creation cost (100,000 entities).
- Simple Iteration – spawning entities with
PositionandVelocityand performing a simple update loop. - Fragmented Iteration – spawning a few types of components (
A,B,C,Data) to simulate data fragmentation, then iterating over one component. - Heavy Compute – spawning entities with a
Transformmatrix and performing a CPU-heavy inner loop per entity. - CRUD Add/Remove – measuring the cost of adding and removing a component (
B) on entities that already have another component (A).
Each section below embeds the violin plot generated by Criterion, highlighting the distribution of iteration times for that test.
Entities Created: 100,000
This chart shows the distribution of times taken to spawn 100,000 entities for each ECS implementation.
Operations:
- Spawn 100,000 entities with
PositionandVelocity. - Iterate and update each
Positionby its correspondingVelocity.
Setup:
- Spawn
FRAGMENTED_ENTITIES_PER_TYPEentities per component type (A,B,C) each paired withData. - Iterate over all
Datacomponents and perform a simple multiplication.
Setup:
- Spawn 1,000 entities with a 4×4
Transformmatrix. - Perform
HEAVY_COMPUTE_ITERATIONS(100) inner-loop additions on the first element of the matrix.
Operations:
- Spawn 100,000 entities with component
A. - Add component
Bto each entity. - Remove component
Bfrom each entity.
Run all benchmarks with:
cargo benchResults will appear in the target/criterion directory.