ach - why we do not put attention to what we are doing???...
Ach, humans don't want to be fast, they just CTRL+C and CTRL+V, shit over shit, but it is working so what do you want a...!!!
see this snippet:
Is there anything suspicious for you?
NO???
Yesterday I was reading Aaron Stannard blog entry about DRY and above snippet just jumped at me from the corner of my screen. DRY DRY DRY.
Now: what's wrong with this one?
- It is not human friendly (formatting)
- It is not CPU friendly as there are two string interpolations instead of one
- we could introduce a helper variable to make it nicer to read (and this is a bit of WTF - see below)
So what we can do with this? Firstly use a single interpolation with a proper formatting like {date:MMM-yy}, this will do the job nicely and we don't need to decipher two statements to get the output when reading the code, now we also could format it a bit, so it is not spread on the wide screen edge to edge...
So what do you think about this:
I decided also to create something that will be human friendly, run benchmark and WTF...
What was going on under the hood of C# was something that I did not expect. To connected some pieces of string, the compiler is calling string.Concat what means, that calling an abstraction adds compute and memory pressure.
So what is going on here?
Let's see the C# 1.0 syntax for those snippets.
So in my small brain all the circuits are on fire now, as the smallest generated code is the slowest one, as it is calling an abstract function to join/concat the results.
As we can see on the benchmark results - removing an extra call to format our date is the key for gaining some CPU ticks.
Comments
Post a Comment