Skip to content

Performance

Prism provides comprehensive performance features for fast test execution and performance analysis.

Run tests across multiple worker processes:

Terminal window
vendor/bin/prism test --parallel 4

Or use the short flag:

Terminal window
vendor/bin/prism test -j 4
  1. Test files divided into batches
  2. Each batch runs in separate PHP process
  3. Results collected and merged
  4. Total execution time significantly reduced
Terminal window
# Use CPU core count
vendor/bin/prism test -j $(nproc)
# Conservative (50% of cores)
vendor/bin/prism test -j $(($(nproc) / 2))
# Maximum performance
vendor/bin/prism test -j $(nproc --all)
Terminal window
# Sequential execution
vendor/bin/prism test
# Time: 45.2s
# Parallel with 4 workers
vendor/bin/prism test -j 4
# Time: 12.8s (3.5x faster)
# Parallel with 8 workers
vendor/bin/prism test -j 8
# Time: 7.1s (6.4x faster)

Identify slowest tests with performance profiling:

Terminal window
vendor/bin/prism test --profile
Test Performance Profile
Slowest Tests:
1. complex-nested-validation (2.145s)
2. large-array-validation (1.832s)
3. recursive-schema-test (1.456s)
4. deep-object-validation (0.987s)
5. pattern-matching-test (0.654s)
Total Tests: 1,247
Average Duration: 0.023s
Median Duration: 0.012s
  • Identify bottlenecks: Find slow tests to optimize
  • Monitor performance: Track test suite speed over time
  • CI optimization: Prioritize fast tests in pipelines

Save and compare performance baselines:

Terminal window
vendor/bin/prism test --baseline

Save with custom name:

Terminal window
vendor/bin/prism test --baseline "pre-optimization"
Terminal window
vendor/bin/prism test --compare

Compare against named baseline:

Terminal window
vendor/bin/prism test --compare "pre-optimization"
Benchmark Comparison: default
Performance Changes:
Total Duration: 45.2s → 38.7s (14.4% faster)
Average Test: 0.036s → 0.031s (13.9% faster)
Significant Changes:
✓ complex-validation: 2.145s → 1.234s (42.5% faster)
✓ array-processing: 1.832s → 1.123s (38.7% faster)
✗ string-validation: 0.234s → 0.387s (65.4% slower)
Tests Analyzed: 1,247
Improved: 892 (71.5%)
Degraded: 123 (9.9%)
Unchanged: 232 (18.6%)
Terminal window
# Save baseline before optimization
vendor/bin/prism test --baseline "before-cache"
# Make optimizations to validator
vim src/Validator.php
# Compare performance
vendor/bin/prism test --compare "before-cache"

Run only changed tests for fast iteration:

Terminal window
vendor/bin/prism test --incremental
  1. Tracks file modification times
  2. Identifies changed test files
  3. Only runs tests from changed files
  4. Significantly faster during development
Terminal window
# First run - all tests execute
vendor/bin/prism test --incremental
# Time: 45.2s
# Make small change to one test file
vim tests/validation/strings.json
# Only changed file tests run
vendor/bin/prism test --incremental
# Time: 0.8s (56x faster)

Cache stored in .prism/incremental-cache.json:

{
"tests/validation/strings.json": 1703001234,
"tests/validation/numbers.json": 1703001156,
"tests/validation/objects.json": 1703000987
}

Clear cache to force full run:

Terminal window
rm .prism/incremental-cache.json

Maximize performance by combining features:

Fast iteration with incremental mode and watch:

Terminal window
vendor/bin/prism test --incremental --watch

Parallel execution with profiling:

Terminal window
vendor/bin/prism test -j 8 --profile

Baseline comparison with profiling:

Terminal window
vendor/bin/prism test --compare "main" --profile

Automatically re-run tests when files change:

Terminal window
vendor/bin/prism test --watch
  1. Runs initial test suite
  2. Monitors test files for changes
  3. Automatically re-runs tests on change
  4. Continues until interrupted (Ctrl+C)
[12:34:56] Initial run completed (45.2s)
[12:35:12] Watching for changes...
[12:36:08] Change detected in tests/validation/strings.json
[12:36:08] Re-running tests...
[12:36:09] Tests completed (0.8s)
[12:36:09] Watching for changes...

Combine watch mode with other features:

Terminal window
# Watch with incremental testing
vendor/bin/prism test --watch --incremental
# Watch with specific filter
vendor/bin/prism test --watch --filter "string"
# Watch with failures only
vendor/bin/prism test --watch --failures
.github/workflows/tests.yml
- name: Run Tests
run: vendor/bin/prism test -j ${{ steps.cpu.outputs.count }}

Monitor test suite performance:

Terminal window
# Weekly baseline
vendor/bin/prism test --baseline "$(date +%Y-%m-%d)"
# Compare against last week
vendor/bin/prism test --compare "$(date -d '7 days ago' +%Y-%m-%d)"

Use profiling to identify and optimize:

Terminal window
vendor/bin/prism test --profile | grep -A 10 "Slowest Tests"

Always use incremental mode when developing:

Terminal window
alias prism-dev="vendor/bin/prism test --incremental --watch"

Profile specific test subsets:

Terminal window
vendor/bin/prism test --filter "validation" --profile

Total time from start to finish:

Terminal window
vendor/bin/prism test
# Total execution time: 45.234s

Individual test execution times:

Terminal window
vendor/bin/prism test --profile
# Shows per-test durations

Tests executed per second:

Terminal window
# 1,247 tests in 45.2s = 27.6 tests/second