<br><div class="gmail_quote">On Fri, Jan 16, 2009 at 12:06 PM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c"><br>
> (define-struct byte-port (bytes port) #:property prop:input-port 1)<br>
><br>
> Are there any issues (cost, synchronization, etc) with using port structs<br>
> this way that I need to think about?<br>
<br>
</div></div>No --- that should work well. There is an overhead in using the wrapped<br>
port, but it's small compared to most any operation on the port.<br>
<font color="#888888"></font></blockquote><div><br>Thanks for verifying, Matthew. I did a quick test and found that the overhead is minimal. I also compared against `substring` as reference, and found that regular string port still has a bit of overhead above substring. Is the overhead due to synchronization primitives?<br>
<br>Thanks,<br>yc<br><br>(define s "this is a string that we are going to read and peek from")<br>(define-struct wport (inner port) #:property prop:input-port 1)<br>(define (open-input-wport s)<br> (make-wport s ((cond ((string? s) open-input-string)<br>
((bytes? s) open-input-bytes)<br> (else (error 'open-input-wport "Unknown type: ~a" s))) s)))<br><br>(define (test-port in count)<br> (for ((i (in-range 0 count)))<br>
(read-bytes 50 in)<br> (file-position in 0)))<br><br>(define (test-string s count)<br> (for ((i (in-range 0 count)))<br> (substring s 0 50)))<br><br>(define (test count)<br> (let ((in1 (open-input-string s))<br>
(in2 (open-input-wport s)))<br> (time (test-port in1 count))<br> (time (test-port in2 count))<br> (time (test-string s count))<br> ))<br><br>(test 500)<br>;; cpu time: 0 real time: 0 gc time: 0 ;; string port<br>
;; cpu time: 1 real time: 1 gc time: 0 ;; wrapped port<br>;; cpu time: 0 real time: 0 gc time: 0 ;; substring<br><br>(test 5000)<br>;; cpu time: 3 real time: 4 gc time: 0<br>;; cpu time: 36 real time: 35 gc time: 31<br>;; cpu time: 2 real time: 2 gc time: 0<br>
<br>(test 50000)<br>;; cpu time: 30 real time: 30 gc time: 0<br>;; cpu time: 43 real time: 43 gc time: 1<br>;; cpu time: 14 real time: 14 gc time: 0<br><br>(test 500000)<br>;; cpu time: 195 real time: 195 gc time: 4<br>;; cpu time: 291 real time: 291 gc time: 4<br>
;; cpu time: 134 real time: 134 gc time: 7<br><br>(test 5000000)<br>;; cpu time: 1982 real time: 1982 gc time: 64<br>;; cpu time: 3081 real time: 3080 gc time: 69<br>;; cpu time: 1464 real time: 1465 gc time: 205<br><br></div>
</div>