Skip to content

String#rindex has poor performance for pathological cases #1140

@shepmaster

Description

@shepmaster

When calling rindex on a long string that does not ever match and has a non-single-byte character, the behavior seems to be O(N^2). MRI's behavior appears to be O(N).

MRI 1.9.3-p448

length       user     system      total        real
10       0.000000   0.000000   0.000000 (  0.000004)
100      0.000000   0.000000   0.000000 (  0.000005)
1000     0.000000   0.000000   0.000000 (  0.000014)
10000    0.000000   0.000000   0.000000 (  0.000097)
100000   0.000000   0.000000   0.000000 (  0.000942)

JRuby 1.7.5

length       user     system      total        real
10       0.000000   0.000000   0.000000 (  0.000000)
100      0.000000   0.000000   0.000000 (  0.001000)
1000     0.000000   0.000000   0.000000 (  0.000000)
10000    0.040000   0.000000   0.040000 (  0.026000)
100000   2.620000   0.000000   2.620000 (  2.625000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions