regexp benchmarks begin/end of anchors

This commit is contained in:
s.kamardin 2016-01-20 17:41:22 +03:00
parent 0de106b322
commit f98a889826
2 changed files with 17 additions and 17 deletions

View File

@ -12,40 +12,40 @@ import (
const ( const (
pattern_all = "[a-z][!a-x]*cat*[h][!b]*eyes*" pattern_all = "[a-z][!a-x]*cat*[h][!b]*eyes*"
regexp_all = `[a-z][^a-x].*cat.*[h][^b].*eyes.*` regexp_all = `^[a-z][^a-x].*cat.*[h][^b].*eyes.*$`
fixture_all = "my cat has very bright eyes" fixture_all = "my cat has very bright eyes"
pattern_plain = "google.com" pattern_plain = "google.com"
regexp_plain = `google\.com` regexp_plain = `^google\.com$`
fixture_plain = "google.com" fixture_plain = "google.com"
pattern_multiple = "https://*.google.*" pattern_multiple = "https://*.google.*"
regexp_multiple = `https:\/\/.*\.google\..*` regexp_multiple = `^https:\/\/.*\.google\..*$`
fixture_multiple = "https://account.google.com" fixture_multiple = "https://account.google.com"
pattern_alternatives = "{https://*.google.*,*yandex.*,*yahoo.*,*mail.ru}" pattern_alternatives = "{https://*.google.*,*yandex.*,*yahoo.*,*mail.ru}"
regexp_alternatives = `(https:\/\/.*\.google\..*|.*yandex\..*|.*yahoo\..*|.*mail\.ru)` regexp_alternatives = `^(https:\/\/.*\.google\..*|.*yandex\..*|.*yahoo\..*|.*mail\.ru)$`
fixture_alternatives = "http://yahoo.com" fixture_alternatives = "http://yahoo.com"
pattern_alternatives_suffix = "{https://*gobwas.com,http://exclude.gobwas.com}" pattern_alternatives_suffix = "{https://*gobwas.com,http://exclude.gobwas.com}"
regexp_alternatives_suffix = `(https:\/\/.*gobwas\.com|http://exclude.gobwas.com)` regexp_alternatives_suffix = `^(https:\/\/.*gobwas\.com|http://exclude.gobwas.com)$`
fixture_alternatives_suffix_first = "https://safe.gobwas.com" fixture_alternatives_suffix_first = "https://safe.gobwas.com"
fixture_alternatives_suffix_second = "http://exclude.gobwas.com" fixture_alternatives_suffix_second = "http://exclude.gobwas.com"
pattern_prefix = "abc*" pattern_prefix = "abc*"
regexp_prefix = `abc.*` regexp_prefix = `^abc.*$`
pattern_suffix = "*def" pattern_suffix = "*def"
regexp_suffix = `.*def` regexp_suffix = `^.*def$`
pattern_prefix_suffix = "ab*ef" pattern_prefix_suffix = "ab*ef"
regexp_prefix_suffix = `ab.*ef` regexp_prefix_suffix = `^ab.*ef$`
fixture_prefix_suffix = "abcdef" fixture_prefix_suffix = "abcdef"
pattern_alternatives_combine_lite = "{abc*def,abc?def,abc[zte]def}" pattern_alternatives_combine_lite = "{abc*def,abc?def,abc[zte]def}"
regexp_alternatives_combine_lite = `(abc.*def|abc.def|abc[zte]def)` regexp_alternatives_combine_lite = `^(abc.*def|abc.def|abc[zte]def)$`
fixture_alternatives_combine_lite = "abczdef" fixture_alternatives_combine_lite = "abczdef"
pattern_alternatives_combine_hard = "{abc*[a-c]def,abc?[d-g]def,abc[zte]?def}" pattern_alternatives_combine_hard = "{abc*[a-c]def,abc?[d-g]def,abc[zte]?def}"
regexp_alternatives_combine_hard = `(abc.*[a-c]def|abc.[d-g]def|abc[zte].def)` regexp_alternatives_combine_hard = `^(abc.*[a-c]def|abc.[d-g]def|abc[zte].def)$`
fixture_alternatives_combine_hard = "abczqdef" fixture_alternatives_combine_hard = "abczqdef"
) )

View File

@ -112,13 +112,13 @@ The same things with `regexp` package:
Pattern | Fixture | Operations | Speed (ns/op) Pattern | Fixture | Operations | Speed (ns/op)
--------|---------|------------|-------------- --------|---------|------------|--------------
`[a-z][^a-x].*cat.*[h][^b].*eyes.*` | `my cat has very bright eyes` | 500000 | 2762 `^[a-z][^a-x].*cat.*[h][^b].*eyes.*$` | `my cat has very bright eyes` | 500000 | 2553
`https:\/\/.*\.google\..*` | `https://account.google.com` | 1000000 | 1191 `^https:\/\/.*\.google\..*$` | `https://account.google.com` | 1000000 | 1205
`(https:\/\/.*\.google\..*|.*yandex\..*|.*yahoo\..*|.*mail\.ru)` | `http://yahoo.com` | 1000000 | 1444 `^(https:\/\/.*\.google\..*|.*yandex\..*|.*yahoo\..*|.*mail\.ru)$` | `http://yahoo.com` | 1000000 | 1435
`(https:\/\/.*gobwas\.com|http://exclude.gobwas.com)` | `https://safe.gobwas.com` | 1000000 | 1037 `^(https:\/\/.*gobwas\.com|http://exclude.gobwas.com)$` | `https://safe.gobwas.com` | 1000000 | 1039
`abc.*` | `abcdef` | 3000000 | 414 `^abc.*$` | `abcdef` | 3000000 | 275
`.*def` | `abcdef` | 5000000 | 276 `^.*def$` | `abcdef` | 5000000 | 464
`ab.*ef` | `abcdef` | 5000000 | 352 `^ab.*ef$` | `abcdef` | 5000000 | 395
[godoc-image]: https://godoc.org/github.com/gobwas/glob?status.svg [godoc-image]: https://godoc.org/github.com/gobwas/glob?status.svg
[godoc-url]: https://godoc.org/github.com/gobwas/glob [godoc-url]: https://godoc.org/github.com/gobwas/glob