Bloqr Compiler Benchmarks
Bloqr Compiler Benchmarks
This document describes the benchmark suite for the bloqr-backend project.
Overview
The benchmark suite covers the following areas:
-
Utility Functions - Core utilities for rule parsing and manipulation
RuleUtils- Rule parsing, validation, and conversionStringUtils- String manipulation operationsWildcard- Pattern matching (plain, wildcard, regex)
-
Transformations - Filter list transformation operations
DeduplicateTransformation- Remove duplicate rulesCompressTransformation- Convert and compress rulesRemoveCommentsTransformation- Strip commentsValidateTransformation- Validate rule syntaxRemoveModifiersTransformation- Remove unsupported modifiersTrimLinesTransformation- Trim whitespaceRemoveEmptyLinesTransformation- Remove empty lines- Chained transformations (real-world pipelines)
Running Benchmarks
Run All Benchmarks
deno bench --allow-read --allow-write --allow-net --allow-envRun Specific Benchmark Files
# Utility benchmarksdeno bench src/utils/RuleUtils.bench.tsdeno bench src/utils/StringUtils.bench.tsdeno bench src/utils/Wildcard.bench.ts
# Transformation benchmarksdeno bench src/transformations/transformations.bench.tsRun Benchmarks by Group
Deno allows filtering benchmarks by group name:
# Run only RuleUtils isComment benchmarksdeno bench --filter "isComment"
# Run only Deduplicate transformation benchmarksdeno bench --filter "deduplicate"
# Run only chained transformation benchmarksdeno bench --filter "chained"Generate JSON Output
For CI/CD integration or further analysis:
deno bench --json > benchmark-results.jsonBenchmark Structure
Each benchmark file follows this structure:
- Setup - Sample data and configurations
- Individual Operations - Test single operations with various inputs
- Batch Operations - Test operations on multiple items
- Real-world Scenarios - Test common usage patterns
Benchmark Groups
Benchmarks are organized into groups for easy filtering:
RuleUtils Groups
isComment- Comment detectionisAllowRule- Allow rule detectionisJustDomain- Domain validationisEtcHostsRule- Hosts file detectionnonAscii- Non-ASCII character handlingpunycode- Punycode conversionparseTokens- Token parsingextractHostname- Hostname extractionloadEtcHosts- Hosts file parsingloadAdblock- Adblock rule parsingbatch- Batch processing
StringUtils Groups
substringBetween- Substring extractionsplit- Delimiter splitting with escapesescapeRegExp- Regex escapingisEmpty- Empty string checkstrim- Whitespace trimmingbatch- Batch operationsrealworld- Real-world usage
Wildcard Groups
creation- Pattern creationplainMatch- Plain string matchingwildcardMatch- Wildcard pattern matchingregexMatch- Regex pattern matchinglongStrings- Long string performanceproperties- Property accessrealworld- Filter list patternscomparison- Pattern type comparison
Transformation Groups
deduplicate- Deduplicationcompress- CompressionremoveComments- Comment removalvalidate- ValidationremoveModifiers- Modifier removaltrimLines- Line trimmingremoveEmptyLines- Empty line removalchained- Chained transformations
Performance Tips
When analyzing benchmark results:
- Look for Regressions - Compare results across commits to catch performance regressions
- Focus on Hot Paths - Prioritize optimizing frequently-called operations
- Consider Trade-offs - Balance performance with code readability and maintainability
- Test with Real Data - Supplement benchmarks with real-world filter list data
CI/CD Integration
Add benchmarks to your CI pipeline:
# Example GitHub Actions- name: Run Benchmarks run: deno bench --allow-read --allow-write --allow-net --allow-env --json > benchmarks.json
- name: Upload Results uses: actions/upload-artifact@v3 with: name: benchmark-results path: benchmarks.jsonInterpreting Results
Deno’s benchmark output shows:
- Time/iteration - Average time per benchmark iteration
- Iterations - Number of iterations run
- Standard deviation - Consistency of results
Lower times and smaller standard deviations indicate better performance.
Adding New Benchmarks
When adding new features, include benchmarks:
- Create or update the relevant
.bench.tsfile - Follow existing naming conventions
- Use descriptive benchmark names
- Add to an appropriate group
- Include various input sizes (small, medium, large)
- Test edge cases
Example:
Deno.bench('MyComponent - operation description', { group: 'myGroup' }, () => { // Setup const component = new MyComponent(); const input = generateTestData();
// Benchmark component.process(input);});Baseline Expectations
Approximate performance baselines (your mileage may vary):
- RuleUtils.isComment: ~100-500ns per call
- RuleUtils.parseRuleTokens: ~1-5µs per call
- Wildcard plain string match: ~50-200ns per call
- Deduplicate 1000 rules: ~1-10ms
- Compress 500 rules: ~5-20ms
- Full pipeline 1000 rules: ~10-50ms
These are rough guidelines - actual performance depends on hardware, input data, and Deno version.