Lea Verou on Nostr: When doing case-insensitive matching of a needle (string) against a haystack ...
When doing case-insensitive matching of a needle (string) against a haystack (potentially large array of strings), which is faster:
1. toLowerCase() (once on needle, then per each item in the haystack)
2. Create regex with i flag, use regex.test()
I would guess 1, but haven't checked. Does anyone know of any benchmark?
Published at
2024-03-13 17:36:06Event JSON
{
"id": "3e98ff6323eb434ed5924af089e51e48fde38f631a9fa17eb0f153beea17ab20",
"pubkey": "deb27057e60b8d796302849309a7c542aa1c718108be4813086deaf9139dff76",
"created_at": 1710351366,
"kind": 1,
"tags": [
[
"proxy",
"https://front-end.social/users/leaverou/statuses/112089587141302171",
"activitypub"
]
],
"content": "When doing case-insensitive matching of a needle (string) against a haystack (potentially large array of strings), which is faster:\n1. toLowerCase() (once on needle, then per each item in the haystack)\n2. Create regex with i flag, use regex.test()\n\nI would guess 1, but haven't checked. Does anyone know of any benchmark?",
"sig": "383cd1922b6a20a816dc0e2f1815108a0153e49ec916e632979e4162c894979ce67da67e43a3e6f0c55923480b2f24777827fac53ccf0bc91e787a78b8a7fc16"
}