2020. május 4., hétfő 12:23:05 UTC+2 időpontban Vivi a következőt írta: > > Interesting, I didn't know strings.Map could work this way, I have done a > performance benchmark with PHP 7 Pcre2 C is 1,020 nanoseconds and > strings.Map version is 2,888 nanoseconds, not bad improvement over regexp. > If there is a better approach, however, Rust Re2 is just as fast as PHP > Pcre2. > > On Monday, 4 May 2020 17:50:15 UTC+8, Tamás Gulácsi wrote: >> >> 2020. május 4., hétfő 11:26:26 UTC+2 időpontban Vivi a következőt írta: >>> >>> I like to replace one or more characters to one character e.g. to >>> sanitize proper slug title with a dash. >>> >>> On Monday, 4 May 2020 14:24:26 UTC+8, Tamás Gulácsi wrote: >>>> >>>> You just want to remove those characters? Use strings.Map. >>> >>> >> See https://play.golang.org/p/dI6ZFG_mzLV for example. >> > bytes.Map may be faster. But even that is just a handful of lines (https://github.com/golang/go/blob/go1.14.2/src/bytes/bytes.go#L453) so if you really want speed, just copy and tweak it.
I'm not saying that regexps are slow, but they're complex, and where a simple loop with a boolean placeholder satisfies, then we don't need that regexp. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/34e42093-7e26-4002-b7f9-1bb9dcf9817e%40googlegroups.com.