Skip to content

strings: optimize Replace #7617

@rui314

Description

@rui314
What does 'go version' print?
go version devel +62052ebe728b Sun Mar 23 18:58:35 2014 -0700 linux/amd64

We have a patch to improve performance of string.Replace by adding a fast path
(https://golang.org/cl/79200044). We cannot commit this now because of the
feature freeze for Go 1.3. Needs to be reviewed after 1.3.

This is a benchmark result of the patch:

benchmark                        old ns/op    new ns/op    delta
BenchmarkGenericNoMatch               2691          774  -71.24%
BenchmarkGenericMatch1                7920         8151   +2.92%
BenchmarkGenericMatch2               52336        39927  -23.71%
BenchmarkSingleMaxSkipping            1575         1575   +0.00%
BenchmarkSingleLongSuffixFail         1429         1429   +0.00%
BenchmarkSingleMatch                 56228        55444   -1.39%
BenchmarkByteByteNoMatch               568          568   +0.00%
BenchmarkByteByteMatch                 977          972   -0.51%
BenchmarkByteStringMatch              1669         1687   +1.08%
BenchmarkHTMLEscapeNew                 422          422   +0.00%
BenchmarkHTMLEscapeOld                 692          670   -3.18%
BenchmarkByteByteReplaces             8492         8474   -0.21%
BenchmarkByteByteMap                  2817         2808   -0.32%

benchmark                         old MB/s     new MB/s  speedup
BenchmarkSingleMaxSkipping         6345.25      6346.76    1.00x
BenchmarkSingleLongSuffixFail       700.85       700.85    1.00x
BenchmarkSingleMatch                266.77       270.54    1.01x

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions