c# - XmlWriter async methods -
i have found example of async using of xmlwriter within msdn documentation http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx
async task testwriter(stream stream) { xmlwritersettings settings = new xmlwritersettings(); settings.async = true; using (xmlwriter writer = xmlwriter.create(stream, settings)) { await writer.writestartelementasync("pf", "root", "http://ns"); await writer.writestartelementasync(null, "sub", null); await writer.writeattributestringasync(null, "att", null, "val"); await writer.writestringasync("text"); await writer.writeendelementasync(); await writer.writeprocessinginstructionasync("pname", "pvalue"); await writer.writecommentasync("cvalue"); await writer.writecdataasync("cdata value"); await writer.writeendelementasync(); await writer.flushasync(); } }
all know threads , async programming said me slow code , using synchronous write methods faster. have modified code , tested it. have found i'm right , synchronous code faster in 3-4 times on files more 100mb , more 8-10 times faster on files less 10mb on env.
so question there scenario such code usable , gives reasonable profit?
first off, have question benchmarking. 3-4 times slower on 100mb files significant.
but regardless, async
not doing things faster. it's doing else while operation going on. on client side, benefit of responsiveness; on server side, benefit of scalability.
the tradeoff operation slower (but should little slower, not 3-4 times slower). it's you're not using asynchronous stream writing (you have open file stream asynchronously asynchronous stream).
Comments
Post a Comment