[Cache] Using strpbrk() instead of strcspn() is faster #21269

Merged
merged 1 commit into from Jan 13, 2017

Projects

None yet

3 participants

@nicolas-grekas
Member
Q A
Branch? 3.1
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Keys validation using strpbrk is faster.
Eg on some micro bench:

  • isset($a[strcspn($a, '{}()/\@:')]): 278ms
  • false !== strpbrk($a, '{}()/\@:'): 183ms
@nicolas-grekas nicolas-grekas added this to the 3.1 milestone Jan 13, 2017
@nicolas-grekas nicolas-grekas [Cache] Using strpbrk() instead of strcspn() is faster
d68c451
@javiereguiluz
Member

👍

Status: reviewed

@nicolas-grekas nicolas-grekas merged commit d68c451 into symfony:3.1 Jan 13, 2017

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details
@nicolas-grekas nicolas-grekas added a commit that referenced this pull request Jan 13, 2017
@nicolas-grekas nicolas-grekas bug #21269 [Cache] Using strpbrk() instead of strcspn() is faster (ni…
…colas-grekas)

This PR was merged into the 3.1 branch.

Discussion
----------

[Cache] Using strpbrk() instead of strcspn() is faster

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Keys validation using strpbrk is faster.
Eg on some micro bench:
- `isset($a[strcspn($a, '{}()/\@:')])`: 278ms
- `false !== strpbrk($a, '{}()/\@:')`: 183ms

Commits
-------

d68c451 [Cache] Using strpbrk() instead of strcspn() is faster
cbb5332
@nicolas-grekas nicolas-grekas deleted the nicolas-grekas:cache-strpbrk branch Jan 13, 2017
This was referenced Jan 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment