Share Link
Copied to clipboard
Embed on Your Page
Copied to clipboard
We Stand with Ukraine
[Fork] .NET Fiddle Newsletter #2: Sync vs async vs parallel by Ewerton

============================

MakeBreakfastSync


NOTE: The number before the time is current threadId

1 00:00.000   MakeBreakfastSync Start
1 00:00.007   BoilCoffee Start
1 00:00.108   BoilCoffee End
1 00:00.108   ToastBread Start
1 00:00.208   ToastBread End
1 00:00.208   FryEggs Start
1 00:00.310   FryEggs End
1 00:00.311   MakeBreakfastSync End

Total time: 311.7173ms


============================

MakeBreakfastAsync

NOTE: tasks maybe using different threads provided by ThreadPool, but unlike parallel programming, it is only one thread at a time

1 00:00.000   MakeBreakfastAsync Start
1 00:00.000   BoilCoffeeAsync Start
1 00:00.003   ToastBreadAsync Start
1 00:00.004   FryEggsAsync Start
5 00:00.103   BoilCoffeeAsync End
5 00:00.104   ToastBreadAsync End
5 00:00.105   FryEggsAsync End
5 00:00.105   MakeBreakfastAsync End

Total time: 105.1969ms


============================

MakeBreakfastParallel

Available processors: 4

Using processors: 2

1 00:00.000   MakeBreakfastParallel Start
1 00:00.006   BoilCoffee Start
5 00:00.007   ToastBread Start
1 00:00.107   BoilCoffee End
5 00:00.107   ToastBread End
1 00:00.107   FryEggs Start
1 00:00.207   FryEggs End

MakeBreakfastParallel End


Total time: 207.7665ms
Cached Result
Last Run: 7:57:47 am
Compile: 0.014s
Execute: 0.7s
Memory: 5.52Mb
CPU: 0.714s