Bad news: the optimizer is moving your functions outside the loop. for _ in 0.. Looking at the assembly... the call to `flatuseStruct` is moved outside the loop in Release builds. You're only measuring 1 thousand iterations of `flatuseStruct`, not 1 million. Your red flag should have been this: > One million times decoding of a small object graph took 0.35ms That's literally impossible. That's doing 2.8 billion itera…
10 thousand times faster Swift
31–37 of 37 posts
Re: 10 thousand times faster Swift
#32Doing benchmarks without knowing what is doing, without understand what is happening and then talking about faster than C only shows naivité. Hope you will use of this mistake to learn how things work and to investigate more in detail before announcing misleading and erroneus information. I can understand the desire to beat C and that this comes from detaching software from hardware obscuring the basis of software an…
The writer disbelieved their own results, got others to double and triple check their work, and when the correct explanation emerged, published a correction. I think you're being overly harsh (and, in the end, the results were very close to C).
No they didn't.
"To be honest it is hard for me to say, how exactly it happened that we got 70 times faster than C, but it is a measurable fact."'
You also don't publish a headline "10,000 times faster Swift" if you don't believe your own results.
At best, this is click-bait.
Re: 10 thousand times faster Swift
#33Earlier quoted context omitted.
The writer disbelieved their own results, got others to double and triple check their work, and when the correct explanation emerged, published a correction. I think you're being overly harsh (and, in the end, the results were very close to C).
> The writer disbelieved their own results No they didn't. "To be honest it is hard for me to say, how exactly it happened that we got 70 times faster than C, but it is a measurable fact. "' You also don't publish a headline "10,000 times faster Swift" if you don't believe your own results. At best, this is click-bait.
Re: 10 thousand times faster Swift
#34Earlier quoted context omitted.
The writer disbelieved their own results, got others to double and triple check their work, and when the correct explanation emerged, published a correction. I think you're being overly harsh (and, in the end, the results were very close to C).
> The writer disbelieved their own results No they didn't. "To be honest it is hard for me to say, how exactly it happened that we got 70 times faster than C, but it is a measurable fact. "' You also don't publish a headline "10,000 times faster Swift" if you don't believe your own results. At best, this is click-bait.
The blog post is in deed titled "10,000 times faster Swift". I though it will be a catchy title even though 6 seconds to 0.35 ms is not factor of 10,000.
I thought about renaming the title to 500 times faster Swift, which would be rathe more accurate insight of current findings, but than what the hack. It's a blog post. I didn't published a scientific paper. I just reflected on my resent work.
The main points of the Blog posts wehere anyways about how it is possible to make low level optimisations to make Swift programs faster. And as a matter of fact the Loop-invariant code motion was a valid technique to get the same result. Result being sum of payload content. The compiler was smarter than me. It gave me the same result doing 250times less work. I find it impressive.
I must be honest I am not fluent in assembly this is why I could not figure it out by myself.
Was I suspicious? Absolutely!!! But the facts were in my face.
Shouldn't I publish an article, where I am not sure why I got what I got? If I wouldn't publish the article, I would not figured out the truth and wouldn't learned form this experience.
And after all, this post is about performance pitfalls in Swift language. The comparison with C was almost accidental. I would compare it with C++ if I would have a Windows machine, as the benchmark for C++ project has Windows specific code. I also consulted with the author of flatcc, who is much more relaxed about my blog post than you are :)
This blog post is about learning something. I learned something before I wrote this post I shared it and now I learned even more.
You should try it yourself.
Maybe not as satisfying as criticising, but it also has it's moments.
Re: 10 thousand times faster Swift
#35Earlier quoted context omitted.
> The writer disbelieved their own results No they didn't. "To be honest it is hard for me to say, how exactly it happened that we got 70 times faster than C, but it is a measurable fact. "' You also don't publish a headline "10,000 times faster Swift" if you don't believe your own results. At best, this is click-bait.
The good thing about any narrative, it resonates with different people on different levels. The blog post is in deed titled "10,000 times faster Swift". I though it will be a catchy title even though 6 seconds to 0.35 ms is not factor of 10,000. I thought about renaming the title to 500 times faster Swift, which would be rathe more accurate insight of current findings, but than what the hack. It's a blog post. I didn…
Re: 10 thousand times faster Swift
#36Earlier quoted context omitted.
The writer disbelieved their own results, got others to double and triple check their work, and when the correct explanation emerged, published a correction. I think you're being overly harsh (and, in the end, the results were very close to C).
> The writer disbelieved their own results No they didn't. "To be honest it is hard for me to say, how exactly it happened that we got 70 times faster than C, but it is a measurable fact. "' You also don't publish a headline "10,000 times faster Swift" if you don't believe your own results. At best, this is click-bait.
Re: 10 thousand times faster Swift
#37> ...Swift being as fast or even faster than C... Rather unlikely. To get “faster than C” you need to hand-code in assembler, and know your target CPU really well to outsmart the compiler. One advantage of C is that it's relatively easy to see what the CPU does when you look at the source. In Swift, this is no longer the case. So, unless you know Swift really well, being “as fast as C” doesn't come easily. One thing…
> To get “faster than C” you need to hand-code in assembler, and know your target CPU really well to outsmart the compiler. Ada compilers can beat C compilers, and languages with some restrictions such as Fortran can beat C.