Ah, I didn't know one could just write a function for the guard... but
that makes a lot of sense!

Sam Tobin-Hochstadt writes:

> The issue is that `struct-guard/c` is slow. If you just write a
> function as a guard it's faster than `struct/contract`.
>
> Sam
>
> On Wed, Sep 2, 2020 at 3:41 PM Christopher Lemmer Webber
> <cweb...@dustycloud.org> wrote:
>>
>> I tested the following:
>>
>>   (struct foo (bar baz)
>>     #:guard (struct-guard/c any/c list?))
>>
>> and:
>>
>>   (struct/contract foo ([bar any/c]
>>                         [baz list?]))
>>
>> With the first:
>>
>>   test> (time
>>          (for ([i 1000000])
>>            (foo 'yeah '(buddy))))
>>   cpu time: 2601 real time: 2599 gc time: 7
>>
>> With the second:
>>
>>   test> (time
>>          (for ([i 1000000])
>>            (foo 'yeah '(buddy))))
>>   cpu time: 184 real time: 184 gc time: 13
>>
>> Wow, what the heck?  That's about a 10x difference.  What?!?!?
>> Why would #:guard be so damn slow in comparison?  You'd think they'd be
>> doing the same thing.
>>
>> Unfortunately I can't use #:methods with struct/contract so I'm stuck
>> with the slow one if I want a contract on the struct?
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/873640arw7.fsf%40dustycloud.org.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/87zh67a8cy.fsf%40dustycloud.org.

Reply via email to