On 4 October 2017 at 23:41, oldk1331 <[email protected]> wrote:
>> How does this compare to the cost of testing case "failed" in the old
>> Union(R,"failed") representation?
>
> I did a crude benchmark on failed?, 200 loops over a vector with
> 10^6 elements of failed():
>
> 1. Union(NNI, "failed") 0.40s
> 2. Maybe NNI, 0.38s
> 3. "generic" Maybe NNI, can't be inlined, 1.24s
>
> The problem with "generic" Maybe is that it can't be inlined.
>

It would help me to understand if you presented your benchmark code.
Here is something I just ran:

spage@strix ~ $ fricas -nox
Checking for foreign routines
AXIOM="/usr/local/lib/fricas/target/x86_64-linux-gnu"
spad-lib="/usr/local/lib/fricas/target/x86_64-linux-gnu/lib/libspad.so"
foreign routines found
openServer result 0
                       FriCAS Computer Algebra System
                         Version: FriCAS 2017-08-05
                   Timestamp: Wed Oct  4 20:47:59 EDT 2017
-----------------------------------------------------------------------------
   Issue )copyright to view copyright notices.
   Issue )summary for a summary of useful system commands.
   Issue )quit to leave FriCAS and return to shell.
-----------------------------------------------------------------------------


(1) -> )r maybe-bench.input
)cl co

   All user variables and function definitions have been cleared.
   All )browse facility databases have been cleared.
   Internally cached functions and constructors have been cleared.
   )clear completely is finished.
)set message time on

A:PrimitiveArray Maybe NNI

                                                                   Type: Void
                                                                  Time: 0 sec
A:=new(10^5,failed()$Maybe(NNI));


                              Type: PrimitiveArray(Maybe(NonNegativeInteger))
                                                   Time: 0.03 (OT) = 0.03 sec
for j in 1..10 repeat for i in 0..#A-1 repeat failed? A(i)

                                                                   Type: Void
                                       Time: 4.28 (EV) + 0.01 (OT) = 4.28 sec
)co maybe-bench1.spad

   Compiling FriCAS source code from file
      /home/wspage/maybe-bench1.spad using old system compiler.
...
   MaybeBench1 will be automatically loaded when needed from
      /home/wspage/MAYB1.NRLIB/MAYB1

test1()


   (4)  0
                                                     Type: NonNegativeInteger
                                       Time: 1.56 (EV) + 0.01 (OT) = 1.58 sec
B:PrimitiveArray Union(NNI,"failed")

                                                                   Type: Void
                                                                  Time: 0 sec
B:=new(10^5,"failed"::Union(NNI,"failed"))$PrimitiveArray(Union(NNI,"failed"));


                     Type: PrimitiveArray(Union(NonNegativeInteger,"failed"))
                                                                  Time: 0 sec
for j in 1..10 repeat for i in 0..#B-1 repeat B(i) case "failed"

                                                                   Type: Void
                                                   Time: 3.90 (EV) = 3.90 sec
)co maybe-bench2.spad

   Compiling FriCAS source code from file
      /home/wspage/maybe-bench2.spad using old system compiler.
...
   MaybeBench2 will be automatically loaded when needed from
      /home/wspage/MAYB2.NRLIB/MAYB2

test2()


   (8)  0
                                                     Type: NonNegativeInteger
                                       Time: 0.98 (EV) + 0.01 (OT) = 0.98 sec
)co maybe.spad

   Compiling FriCAS source code from file /home/wspage/maybe.spad using
      old system compiler.
...
   Maybe is now explicitly exposed in frame frame1
   Maybe will be automatically loaded when needed from
      /home/wspage/MAYBE.NRLIB/MAYBE

C:PrimitiveArray Maybe NNI

                                                                   Type: Void
                                                                  Time: 0 sec
C:=new(10^5,empty()$Maybe(NNI));


                              Type: PrimitiveArray(Maybe(NonNegativeInteger))
                                                   Time: 0.01 (OT) = 0.01 sec
for j in 1..10 repeat for i in 0..#C-1 repeat empty? C(i)

                                                                   Type: Void
                                                   Time: 4.15 (EV) = 4.15 sec
)co maybe-bench3.spad

   Compiling FriCAS source code from file
      /home/wspage/maybe-bench3.spad using old system compiler.
...
   MaybeBench3 is now explicitly exposed in frame frame1
   MaybeBench3 will be automatically loaded when needed from
      /home/wspage/MAYB3.NRLIB/MAYB3

test3()


   (12)  0
                                                     Type: NonNegativeInteger
                                       Time: 0.87 (EV) + 0.01 (OT) = 0.88 sec
(13) ->

This seems to show that testing 'failed?' in 'Maybe(R)' at 4.26 sec is
just a little slower than testing 'case "failed"' in
'Union(R,"failed")' at 3.91 sec.

For comparison I have included my reference implementation of
'Maybe(R)' using 'Rep:=List R' that I sent in an earlier email. In the
interpreter it seems to be intermediate between your Maybe and Union
but when compiled it seems faster than both. Of course using 'List R'
as a representation is not as space efficient as using the domain R
itself but it does have the advantage of having semantics consistent
with Haskell functor.

Bill Page

-- 
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.

Attachment: maybe-bench3.spad
Description: Binary data

Attachment: maybe-bench2.spad
Description: Binary data

Attachment: maybe-bench1.spad
Description: Binary data

Attachment: maybe-bench.input
Description: Binary data

Attachment: maybe.spad
Description: Binary data

Reply via email to