-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: move to commonjs and mirror streamsearch
- Loading branch information
Showing
8 changed files
with
162 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,77 @@ | ||
/* eslint-disable unicorn/no-array-push-push */ | ||
import { Match } from "../src/index.js"; | ||
import StreamSearch from "streamsearch"; | ||
import { Bench } from "tinybench"; | ||
import { Buffer } from "node:buffer"; | ||
"use strict"; | ||
|
||
const bench = new Bench({ time: 5000 }); | ||
const pattern = "exampleexampleexampleexampleexampleexample"; | ||
const longText = | ||
`This is a long text with multiple occurrences of the word example. ` + | ||
`It repeats the word exampleexampleexampleexampleexampleexample several times to ensure we have enough ${"data for the benchmark. Here's another exampleexampleexampleexampleexampleexample.".repeat( | ||
5, | ||
)}`; | ||
let gmatchMatches; | ||
let streamsearchMatches; | ||
const { Match } = require("../src/index.js"); | ||
const StreamSearch = require("streamsearch"); | ||
const { Bench } = require("tinybench"); | ||
|
||
bench | ||
.add("gmatch", () => { | ||
const matches = []; | ||
const search = new Match( | ||
pattern, | ||
(isMatch, data, start) => { | ||
(async () => { | ||
const bench = new Bench({ time: 5000 }); | ||
const pattern = "exampleexampleexampleexampleexampleexample"; | ||
const longText = | ||
`This is a long text with multiple occurrences of the word example. ` + | ||
`It repeats the word exampleexampleexampleexampleexampleexample several times to ensure we have enough ${"data for the benchmark. Here's another exampleexampleexampleexampleexampleexample.".repeat( | ||
5, | ||
)}`; | ||
let gmatchMatches; | ||
let streamsearchMatches; | ||
|
||
bench | ||
.add("gmatch", () => { | ||
const matches = []; | ||
const search = new Match( | ||
pattern, | ||
(isMatch, data, start, end) => { | ||
if (isMatch) { | ||
matches.push(end); | ||
} | ||
}, | ||
Buffer.from, | ||
); | ||
|
||
search.write("exampleexampleexampleexample"); | ||
search.write("fexampleexampleexampleexampleexample"); | ||
search.write( | ||
"exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", | ||
); | ||
search.write("exampleexampleexampleexample"); | ||
search.write("fexampleexampleexampleexampleexample"); | ||
search.write( | ||
"exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", | ||
); | ||
search.write(longText); | ||
search.write(pattern); | ||
|
||
gmatchMatches = matches.length; | ||
}) | ||
.add("streamsearch", () => { | ||
const matches = []; | ||
const search = new StreamSearch(pattern, (isMatch, data, start, end) => { | ||
if (isMatch) { | ||
matches.push(start); | ||
matches.push(end); | ||
} | ||
}, | ||
Buffer.from, | ||
); | ||
}); | ||
|
||
search.write("exampleexampleexampleexample"); | ||
search.write("fexampleexampleexampleexampleexample"); | ||
search.write( | ||
"exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", | ||
); | ||
search.write("exampleexampleexampleexample"); | ||
search.write("fexampleexampleexampleexampleexample"); | ||
search.write( | ||
"exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", | ||
); | ||
search.write(longText); | ||
search.write(pattern); | ||
search.push("exampleexampleexampleexample"); | ||
search.push("fexampleexampleexampleexampleexample"); | ||
search.push( | ||
"exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", | ||
); | ||
search.push("exampleexampleexampleexample"); | ||
search.push("fexampleexampleexampleexampleexample"); | ||
search.push( | ||
"exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", | ||
); | ||
search.push(longText); | ||
search.push(pattern); | ||
|
||
gmatchMatches = matches.length; | ||
}) | ||
.add("streamsearch", () => { | ||
const matches = []; | ||
const search = new StreamSearch(pattern, (isMatch, data, start) => { | ||
if (isMatch) { | ||
matches.push(start); | ||
} | ||
streamsearchMatches = matches.length; | ||
}); | ||
|
||
search.push("exampleexampleexampleexample"); | ||
search.push("fexampleexampleexampleexampleexample"); | ||
search.push( | ||
"exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", | ||
); | ||
search.push("exampleexampleexampleexample"); | ||
search.push("fexampleexampleexampleexampleexample"); | ||
search.push( | ||
"exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", | ||
); | ||
search.push(longText); | ||
search.push(pattern); | ||
|
||
streamsearchMatches = matches.length; | ||
}); | ||
|
||
await bench.warmup(); | ||
await bench.run(); | ||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
globalThis.console.table(bench.table()); | ||
globalThis.console.log("gmatch matches:", gmatchMatches); | ||
globalThis.console.log("streamsearch matches:", streamsearchMatches); | ||
console.table(bench.table()); | ||
console.log("gmatch matches:", gmatchMatches); | ||
console.log("streamsearch matches:", streamsearchMatches); | ||
})(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import grules from "grules"; | ||
import globals from "globals"; | ||
|
||
export default [ | ||
...grules, | ||
{ | ||
languageOptions: { | ||
globals: { | ||
...globals.node, | ||
}, | ||
}, | ||
}, | ||
]; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.