<div dir="ltr">Hi,<div><br></div><div>While trying to benchmark some of my code, I tried to minimize the time spend on predefined IO functions, such as write-byte & friends, by using the port returned by open-output-nowhere, expecting that it would be faster than using, e.g., open-output-bytes, which has to accumulate the output.</div>
<div><br></div><div>However, contrary to my expectations, it turns out that using open-output-nowhere is 10 times slower that using open-output-bytes.</div><div><br></div><div>Here is one example:</div><div><br></div><div>
<div><div>#lang racket</div><div>(define (test i n p)</div><div> (time (for ([l (in-range n)])</div><div> (write-byte i p))))</div><div><br></div><div>(test 123 100000000 (open-output-bytes))</div><div>(test 123 100000000 (open-output-nowhere))</div>
</div></div><div><br></div><div>I'm getting:</div><div><br></div><div><div>cpu time: 2860 real time: 2854 gc time: 32<br></div><div>cpu time: 28906 real time: 28904 gc time: 125</div><div><br></div></div><div>What's causing this difference?</div>
<div><br></div><div>Best,<br>António.</div></div>