## Performance Braces is not only screaming fast, it's also more accurate the other brace expansion libraries. ### Better algorithms Fortunately there is a solution to the ["brace bomb" problem](#brace-matching-pitfalls): _don't expand brace patterns into an array when they're used for matching_. Instead, convert the pattern into an optimized regular expression. This is easier said than done, and braces is the only library that does this currently. **The proof is in the numbers** Minimatch gets exponentially slower as patterns increase in complexity, braces does not. The following results were generated using `braces()` and `minimatch.braceExpand()`, respectively. | **Pattern** | **braces** | **[minimatch](https://github.com/isaacs/minimatch)** | | --- | --- | --- | | `{1..9007199254740991}`[1] | `298 B` (5ms 459μs) | N/A (freezes) | | `{1..1000000000000000}` | `41 B` (1ms 15μs) | N/A (freezes) | | `{1..100000000000000}` | `40 B` (890μs) | N/A (freezes) | | `{1..10000000000000}` | `39 B` (2ms 49μs) | N/A (freezes) | | `{1..1000000000000}` | `38 B` (608μs) | N/A (freezes) | | `{1..100000000000}` | `37 B` (397μs) | N/A (freezes) | | `{1..10000000000}` | `35 B` (983μs) | N/A (freezes) | | `{1..1000000000}` | `34 B` (798μs) | N/A (freezes) | | `{1..100000000}` | `33 B` (733μs) | N/A (freezes) | | `{1..10000000}` | `32 B` (5ms 632μs) | `78.89 MB` (16s 388ms 569μs) | | `{1..1000000}` | `31 B` (1ms 381μs) | `6.89 MB` (1s 496ms 887μs) | | `{1..100000}` | `30 B` (950μs) | `588.89 kB` (146ms 921μs) | | `{1..10000}` | `29 B` (1ms 114μs) | `48.89 kB` (14ms 187μs) | | `{1..1000}` | `28 B` (760μs) | `3.89 kB` (1ms 453μs) | | `{1..100}` | `22 B` (345μs) | `291 B` (196μs) | | `{1..10}` | `10 B` (533μs) | `20 B` (37μs) | | `{1..3}` | `7 B` (190μs) | `5 B` (27μs) | ### Faster algorithms When you need expansion, braces is still much faster. _(the following results were generated using `braces.expand()` and `minimatch.braceExpand()`, respectively)_ | **Pattern** | **braces** | **[minimatch](https://github.com/isaacs/minimatch)** | | --- | --- | --- | | `{1..10000000}` | `78.89 MB` (2s 698ms 642μs) | `78.89 MB` (18s 601ms 974μs) | | `{1..1000000}` | `6.89 MB` (458ms 576μs) | `6.89 MB` (1s 491ms 621μs) | | `{1..100000}` | `588.89 kB` (20ms 728μs) | `588.89 kB` (156ms 919μs) | | `{1..10000}` | `48.89 kB` (2ms 202μs) | `48.89 kB` (13ms 641μs) | | `{1..1000}` | `3.89 kB` (1ms 796μs) | `3.89 kB` (1ms 958μs) | | `{1..100}` | `291 B` (424μs) | `291 B` (211μs) | | `{1..10}` | `20 B` (487μs) | `20 B` (72μs) | | `{1..3}` | `5 B` (166μs) | `5 B` (27μs) | If you'd like to run these comparisons yourself, see [test/support/generate.js](test/support/generate.js). ## Benchmarks ### Running benchmarks Install dev dependencies: ```bash npm i -d && npm benchmark ``` ### Latest results ```bash Benchmarking: (8 of 8) · combination-nested · combination · escaped · list-basic · list-multiple · no-braces · sequence-basic · sequence-multiple # benchmark/fixtures/combination-nested.js (52 bytes) brace-expansion x 4,756 ops/sec ±1.09% (86 runs sampled) braces x 11,202,303 ops/sec ±1.06% (88 runs sampled) minimatch x 4,816 ops/sec ±0.99% (87 runs sampled) fastest is braces # benchmark/fixtures/combination.js (51 bytes) brace-expansion x 625 ops/sec ±0.87% (87 runs sampled) braces x 11,031,884 ops/sec ±0.72% (90 runs sampled) minimatch x 637 ops/sec ±0.84% (88 runs sampled) fastest is braces # benchmark/fixtures/escaped.js (44 bytes) brace-expansion x 163,325 ops/sec ±1.05% (87 runs sampled) braces x 10,655,071 ops/sec ±1.22% (88 runs sampled) minimatch x 147,495 ops/sec ±0.96% (88 runs sampled) fastest is braces # benchmark/fixtures/list-basic.js (40 bytes) brace-expansion x 99,726 ops/sec ±1.07% (83 runs sampled) braces x 10,596,584 ops/sec ±0.98% (88 runs sampled) minimatch x 100,069 ops/sec ±1.17% (86 runs sampled) fastest is braces # benchmark/fixtures/list-multiple.js (52 bytes) brace-expansion x 34,348 ops/sec ±1.08% (88 runs sampled) braces x 9,264,131 ops/sec ±1.12% (88 runs sampled) minimatch x 34,893 ops/sec ±0.87% (87 runs sampled) fastest is braces # benchmark/fixtures/no-braces.js (48 bytes) brace-expansion x 275,368 ops/sec ±1.18% (89 runs sampled) braces x 9,134,677 ops/sec ±0.95% (88 runs sampled) minimatch x 3,755,954 ops/sec ±1.13% (89 runs sampled) fastest is braces # benchmark/fixtures/sequence-basic.js (41 bytes) brace-expansion x 5,492 ops/sec ±1.35% (87 runs sampled) braces x 8,485,034 ops/sec ±1.28% (89 runs sampled) minimatch x 5,341 ops/sec ±1.17% (87 runs sampled) fastest is braces # benchmark/fixtures/sequence-multiple.js (51 bytes) brace-expansion x 116 ops/sec ±0.77% (77 runs sampled) braces x 9,445,118 ops/sec ±1.32% (84 runs sampled) minimatch x 109 ops/sec ±1.16% (76 runs sampled) fastest is braces ``` ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: ```sh \$ npm install && npm test ```