Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Custom DateTimeFormatter for rfc header values #715

Closed
BrennanConroy opened this issue Sep 29, 2016 · 5 comments
Closed

Custom DateTimeFormatter for rfc header values #715

BrennanConroy opened this issue Sep 29, 2016 · 5 comments
Assignees

Comments

@BrennanConroy
Copy link
Member

No description provided.

@davidfowl
Copy link
Member

But less bad 😄

@BrennanConroy
Copy link
Member Author

Exactly, less allocatey

@khellang
Copy link
Contributor

khellang commented Sep 30, 2016

How much does the current method allocate today? There's no way to get this down to less than 29 bytes, right?

EDIT: Just ran a benchmark using a custom formatter and ToString("R"):

image

The code can be found here; https://gist.github.com/khellang/3b32c0fd453616bb2de7edabf06e4413

I can PR it if you want 😄

@aL3891
Copy link

aL3891 commented Oct 3, 2016

We had some optimization fun over in the kestrel channel, here's my version:
https://gist.github.com/aL3891/2644c97e55f2f6c67b1ade15228031b8

Method Median StdDev Scaled Scaled-SD Gen 0 Gen 1 Gen 2 Bytes Allocated/Op
ToStringR 1,130.0891 ns 56.6262 ns 1.00 0.00 2,573.00 - - 280.17
ToRfc1123StringKristian 304.7408 ns 22.0395 ns 0.28 0.02 372.69 - - 40.79
ToRfc1123StringTore 154.4097 ns 9.7327 ns 0.14 0.01 365.19 - - 39.64
ToRfc1123StringAllanv1 180.8173 ns 6.2492 ns 0.16 0.01 347.00 - - 38.02
ToRfc1123StringAllanv2 167.9066 ns 3.9408 ns 0.15 0.01 369.12 - - 40.03
ToRfc1123StringAllanv3 133.9333 ns 2.3357 ns 0.12 0.01 376.04 - - 40.81
ToRfc1123StringAllanv4 125.3757 ns 4.7718 ns 0.11 0.01 376.04 - - 40.81
ToRfc1123StringAllanv1WithBuffer 98.0984 ns 7.4054 ns 0.09 0.01 - - - 0.01
ToRfc1123StringAllanv2WithBuffer 87.8140 ns 2.2064 ns 0.08 0.00 - - - 0.00
ToRfc1123StringAllanv3WithBuffer 53.3263 ns 3.7403 ns 0.05 0.00 - - - 0.00
ToRfc1123StringAllanv4WithBuffer 48.0761 ns 1.4900 ns 0.04 0.00 - - - 0.00

its a little crazy but I think its worth it for the perf (it was a fun exercise in any case) :D would you be interested in a PR?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants