Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compare buffer bytes directly for faster detection #70

Merged
merged 2 commits into from
Dec 6, 2020

Conversation

mgartner
Copy link
Member

@mgartner mgartner commented Dec 6, 2020

compare buffer bytes directly for faster detection

Previously, in order to detect the type of the file, the buffer was
converted to ASCII strings and then compared to hard-coded strings. Now,
the bytes of the buffer are compared directly to hard-coded bytes, which
is more efficient.

name                        old time/op  new time/op  delta
Calipers/png-304x85         90.9µs ± 3%  85.6µs ± 3%   -5.85%  (p=0.008 n=5+5)
Calipers/png-304x85-buffer  2.14µs ± 8%  1.29µs ± 3%  -39.67%  (p=0.008 n=5+5)

reduce number of benchmark cases

Previously the benchmark script ran a benchmark for each PNG file in
test/fixtures. The measurements for all PNGs were roughly the same, so
running a benchmark for each seems redundant. It was also time
consuming. Now, only a single PNG is benchmarked.

Previously the benchmark script ran a benchmark for each PNG file in
`test/fixtures`. The measurements for all PNGs were roughly the same, so
running a benchmark for each seems redundant. It was also time
consuming. Now, only a single PNG is benchmarked.
Previously, in order to detect the type of the file, the buffer was
converted to ASCII strings and then compared to hard-coded strings. Now,
the bytes of the buffer are compared directly to hard-coded bytes, which
is more efficient.

    name                        old time/op  new time/op  delta
    Calipers/png-304x85         90.9µs ± 3%  85.6µs ± 3%   -5.85%  (p=0.008 n=5+5)
    Calipers/png-304x85-buffer  2.14µs ± 8%  1.29µs ± 3%  -39.67%  (p=0.008 n=5+5)
@mgartner mgartner changed the title Faster detect compare buffer bytes directly for faster detection Dec 6, 2020
@mgartner mgartner merged commit 06cffda into calipersjs:master Dec 6, 2020
@mgartner mgartner deleted the faster-detect branch December 6, 2020 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant