c# - Measure cpu intensive time with async code -
we want outsource part of our application external company. these components make async requests external websites , handle content html parsers or regular expressions.
async task do() { var webcontent = await get("http://..."); var match = regex.match(webcontent); if (isxxx(match)) { webcontent = await get("http://other..."); } }
each component different, make 1 request, others lot more. want ensure cpu intensive part (regex, parsing) not take longer 100ms , want test automatically first step in quality ensurance pipeline. there way measure performance without waiting time web requests?
i see 2 solutions @ moment, know if there better approach:
- provide wrapper web requests , measure waiting time. use simple stopwatch measure time , subtract waiting time. difficult soap calls when using generated client classes.
- implement custom synchronization context , measure time here.
are there builtin solutions?
mock io-bound web requests return html string take similar cpu process. e.g. use return task.fromresult(xxx)
task completed. measure method whole.
note can use microsoft fakes replace internal call own method.
Comments
Post a Comment