✅ Async on single-threaded VM, mysterious speedup?
Consider the following code.
This is running on a virtual machine with a single (!) core.
How is it possible that on a single-threaded machine, the version where the tasks run in paralell is faster (see measurements in image)?
The file is large (1.5MB).
Thanks!


51 Replies
better image of the code

I'm not sure if this will answer your question, but the operative system has something known as thread scheduling. It may pause a certain thread and take over another depending on the load and configuration
Sure, but in total, both cases have to do the same amount of work and there is only one thread available
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
it's a blank vm and I don't have shared clipboard
how, though, there is only one CPU core?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I don't understand this explanation
there is only one thread, and the same total amount of work is done in both cases
where does the faster runtime come from?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
what's the better way to benchmark that?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Try BenchmarkDotNet if you want a sophisticated library for benchmarking https://github.com/dotnet/BenchmarkDotNet
IO doesn't require a working thread?
$nothread
There Is No Thread
This is an essential truth of async in its purest form: There is no thread.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
🤯
i thought that some bit of the CPU needs to work on the IO
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
is there anything in the standard library which can accurately time the execution of code?
something like c++'s
std::chrono::steady_clock
?Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
OH right the GC could screw my timing
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
it is mildly annoying that i need a third party library for reliable benchmarks
oh well
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
That's not what I said, I'm just sad some fashion of reliable benchmarking is not included in the C# standard library(ies)
Well, you can use Stopwatch to accurately time intervals.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
But a proper benchmark needs things like JIT warmup.
I see
though the most important thing to learn here is that parts of IO don't need the CPU's participation
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
ah yes as a firm c++ enjoyer I love footguns
i digress
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
reading rn
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
you could say i'm asynchronously reading :kekw:
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I like low-level, sure
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Awesome thanks ❤️
I mean i've been wasting time writing a coroutine executor in C++ recently so this will definetely be helpful information
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
alr this is :pog: ing information
I shall continue reading
Thanks!
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
If you have no further questions, please use /close to mark the forum thread as answered
can i leave this thread around for just a little while to not lose track of the links?
All the close command does is adds a checkmark to the question to mark it as solved, it's not removed
ah good
alr
That said, barely anybody closes their threads anyway, so... :KEKW:
:kekw:
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View