Benchmarks:
Memory usage:
I measured it with ')lisp (sb-ext:get-bytes-consed)'
When storing 100K "failed" values in List,
Union(Integer, "failed") takes 3.2MB memory
Maybe Integer takes 1.6MB memory
I think the "failed" is alloced as String multiple times.
Also see the generated lisp code for subtractIfCan$NNI:
Maybe version, no extra CONS:
(SDEFUN |NNI;subtractIfCan;2$M;4| ((|x| $) (|y| $) ($ |Maybe| $))
(SPROG ((|c| (|Integer|)))
(SEQ (LETT |c| (- |x| |y|) |NNI;subtractIfCan;2$M;4|)
(EXIT (COND ((< |c| 0) *MAYBEFAIL*) ('T |c|))))))
Union version, with extra CONS:
(SDEFUN |NNI;subtractIfCan;2$U;4| ((|x| $) (|y| $) ($ |Union| $ "failed"))
(SPROG ((|c| (|Integer|)))
(SEQ (LETT |c| (- |x| |y|) |NNI;subtractIfCan;2$U;4|)
(EXIT
(COND ((< |c| 0) (CONS 1 "failed")) ('T (CONS 0 |c|)))))))
"unwrap(x)" generates |maybe_unwrap|, "x::R" generates
|check_union2|, and |maybe_unwrap| is slightly simpler than
|check_union2|.
So, Maybe uses less memory and generates better inlined
lisp code than Union.
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.