c# - How to best simulate IO bound work? -


it's easy simulate heavy cpu load.

public void exercisecpu() {   (int = 0; < 999; i++)     (int j= 0; j < 999; j++)       (int k = 0; k < 999; k++)         int x = * j * k;     } 

what's comparable short code block simulating heavy or slow io? in other words, what's technique simulating slow process that's light on cpu?

assuming want test app long delays during io in mocked/intercepted io layer:

thread.sleep simulate non-cpu load fine synchronous io operations, async/await task.delay.

class slowfakedatefromdeviceprovider : idatafromdevice     {   data getfromdevice(...)   {     thread.sleep(1000);     return constructfakedata();   }   ... 

note if need have significant io load - consider unbuffered read of large file (to avoid memory pressure on cache).


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -