Timing comparison between call/cc-safe and non-call/cc-safe procedures Bradley Lucier (07 Aug 2022 05:06 UTC)

Timing comparison between call/cc-safe and non-call/cc-safe procedures Bradley Lucier 07 Aug 2022 05:06 UTC
In this branch:

https://github.com/gambiteer/srfi-231/tree/call-cc-safe

I've implemented

array-copy array-copy!
array-stack array-stack!
array-decurry array-decurry!
array-append array-append!
array-block array-block!

in both call/cc safe and non-call/cc safe (!) versions.  When presented
with only specialized arrays as arguments, the two versions of each
routine do the same thing.

I compared timings of array-copy and array-copy! on big and small
generalized arrays to specialized arrays:

to fixnum arrays (generic-storage-class)
to flonum arrays (f64-storage-class)
to bit arrays (u1-storage-class)
to bit arrays (u8 storage-class)

I also compared timings of array-copy on specialized arrays of the same
size and type (which uses memmove except on arrays of u1-storage-class).

Sometimes array-copy! is faster, as expected, sometimes array-copy is
faster.  As before, memory usage for the "safe" routines is larger
(sometimes much larger) than for the "unsafe" routines.

Overall, I think this approach is worthwhile.  I've sent a pull request
to add this code to the main repository.

Here are the timings.  The test program is attached.

Brad

heine:~/lang/scheme/srfi-231/srfi-231-temp> gsi
Gambit v4.9.4-40-g2c84dc5a

 > (load "generic-arrays")
"/home/lucier/lang/scheme/srfi-231/srfi-231-temp/generic-arrays.o1"
 > (load "time-arrays")
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy
(array-map (lambda (a b c) (fx+ a (fx* b c))) bigfix-A bigfix-B
bigfix-C) generic-storage-class)))
     0.505788 secs real time
     0.505776 secs cpu time (0.450119 user, 0.055657 system)
     6 collections accounting for 0.078554 secs real time (0.067174
user, 0.011389 system)
     504009424 bytes allocated
     52487 minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy!
(array-map (lambda (a b c) (fx+ a (fx* b c))) bigfix-A bigfix-B
bigfix-C) generic-storage-class)))
     0.395898 secs real time
     0.395853 secs cpu time (0.371958 user, 0.023895 system)
     2 collections accounting for 0.018837 secs real time (0.010880
user, 0.007917 system)
     -15988688 bytes allocated
     17305 minor faults
     no major faults

(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy
(array-map (lambda (a b c) (fl+ a (fl* b c))) bigflo-A bigflo-B
bigflo-C) f64-storage-class)))
     0.958457 secs real time
     0.958435 secs cpu time (0.842260 user, 0.116175 system)
     19 collections accounting for 0.400048 secs real time (0.371341
user, 0.028690 system)
     1760009280 bytes allocated
     106047 minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy!
(array-map (lambda (a b c) (fl+ a (fl* b c))) bigflo-A bigflo-B
bigflo-C) f64-storage-class)))
     0.594375 secs real time
     0.594323 secs cpu time (0.574305 user, 0.020018 system)
     23 collections accounting for 0.148164 secs real time (0.136138
user, 0.012034 system)
     1280011744 bytes allocated
     15600 minor faults
     no major faults

(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy
(array-map (lambda (a b c) (fx+ a (fx* b c))) smallfix-A smallfix-B
smallfix-C) generic-storage-class)))
     0.759671 secs real time
     0.759665 secs cpu time (0.752512 user, 0.007153 system)
     26 collections accounting for 0.161501 secs real time (0.157532
user, 0.003953 system)
     1221999952 bytes allocated
     no minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy!
(array-map (lambda (a b c) (fx+ a (fx* b c))) smallfix-A smallfix-B
smallfix-C) generic-storage-class)))
     0.751451 secs real time
     0.751441 secs cpu time (0.751441 user, 0.000000 system)
     18 collections accounting for 0.110944 secs real time (0.110933
user, 0.000000 system)
     880000000 bytes allocated
     no minor faults
     no major faults

(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy
(array-map (lambda (a b c) (fl+ a (fl* b c))) smallflo-A smallflo-B
smallflo-C) f64-storage-class)))
     1.002089 secs real time
     1.001835 secs cpu time (1.001835 user, 0.000000 system)
     52 collections accounting for 0.322556 secs real time (0.322404
user, 0.000000 system)
     2510000000 bytes allocated
     no minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy!
(array-map (lambda (a b c) (fl+ a (fl* b c))) smallflo-A smallflo-B
smallflo-C) f64-storage-class)))
     1.017529 secs real time
     1.017513 secs cpu time (1.017513 user, 0.000000 system)
     46 collections accounting for 0.282159 secs real time (0.282122
user, 0.000000 system)
     2210000000 bytes allocated
     no minor faults
     no major faults

(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy
(array-map (lambda (a b c) (fxior a (fxand b c))) bigu1-A bigu1-B
bigu1-C) u1-storage-class)))
     0.544020 secs real time
     0.543903 secs cpu time (0.535933 user, 0.007970 system)
     7 collections accounting for 0.064200 secs real time (0.064132
user, 0.000034 system)
     480135128 bytes allocated
     9680 minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy!
(array-map (lambda (a b c) (fxior a (fxand b c))) bigu1-A bigu1-B
bigu1-C) u1-storage-class)))
     0.466672 secs real time
     0.466500 secs cpu time (0.466500 user, 0.000000 system)
     no collections
     1263440 bytes allocated
     30 minor faults
     no major faults

(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy
(array-map (lambda (a b c) (fxior a (fxand b c))) smallu1-A smallu1-B
smallu1-C) u1-storage-class)))
     0.848701 secs real time
     0.848648 secs cpu time (0.848648 user, 0.000000 system)
     22 collections accounting for 0.135638 secs real time (0.135595
user, 0.000000 system)
     1128625400 bytes allocated
     no minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy!
(array-map (lambda (a b c) (fxior a (fxand b c))) smallu1-A smallu1-B
smallu1-C) u1-storage-class)))
     0.892397 secs real time
     0.892329 secs cpu time (0.889286 user, 0.003043 system)
     17 collections accounting for 0.104178 secs real time (0.104171
user, 0.000006 system)
     830000000 bytes allocated
     no minor faults
     no major faults

(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy
(array-map (lambda (a b c) (fxior a (fxand b c))) bigu8-A bigu8-B
bigu8-C) u8-storage-class)))
     0.462805 secs real time
     0.462805 secs cpu time (0.462805 user, 0.000000 system)
     8 collections accounting for 0.075027 secs real time (0.075026
user, 0.000000 system)
     481009536 bytes allocated
     300 minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy!
(array-map (lambda (a b c) (fxior a (fxand b c))) bigu8-A bigu8-B
bigu8-C) u8-storage-class)))
     0.401525 secs real time
     0.401487 secs cpu time (0.401487 user, 0.000000 system)
     no collections
     10012640 bytes allocated
     1717 minor faults
     no major faults

(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy
(array-map (lambda (a b c) (fxior a (fxand b c))) smallu8-A smallu8-B
smallu8-C) u8-storage-class)))
     0.752662 secs real time
     0.752507 secs cpu time (0.752507 user, 0.000000 system)
     20 collections accounting for 0.123120 secs real time (0.122990
user, 0.000000 system)
     1078999056 bytes allocated
     240 minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy!
(array-map (lambda (a b c) (fxior a (fxand b c))) smallu8-A smallu8-B
smallu8-C) u1-storage-class)))
     0.804976 secs real time
     0.804683 secs cpu time (0.804683 user, 0.000000 system)
     16 collections accounting for 0.097725 secs real time (0.097708
user, 0.000000 system)
     830000000 bytes allocated
     no minor faults
     no major faults

Raw assignments of specialized-arrays
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy bigfix-B)))
     0.023190 secs real time
     0.023189 secs cpu time (0.023189 user, 0.000000 system)
     1 collection accounting for 0.006333 secs real time (0.006334 user,
0.000000 system)
     56005200 bytes allocated
     1317 minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy bigflo-B)))
     0.022655 secs real time
     0.022652 secs cpu time (0.022652 user, 0.000000 system)
     1 collection accounting for 0.006199 secs real time (0.006200 user,
0.000000 system)
     8004912 bytes allocated
     345 minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy bigu1-B)))
     0.172753 secs real time
     0.172657 secs cpu time (0.172657 user, 0.000000 system)
     no collections
     1256880 bytes allocated
     30 minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i bigiterations)) (array-copy bigu8-B)))
     0.004053 secs real time
     0.004053 secs cpu time (0.004053 user, 0.000000 system)
     no collections
     10005760 bytes allocated
     106 minor faults
     no major faults

(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy
smallfix-B)))
     0.163015 secs real time
     0.162993 secs cpu time (0.162993 user, 0.000000 system)
     10 collections accounting for 0.061650 secs real time (0.061643
user, 0.000000 system)
     424747824 bytes allocated
     no minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy
smallflo-B)))
     0.169046 secs real time
     0.168996 secs cpu time (0.168996 user, 0.000000 system)
     10 collections accounting for 0.061809 secs real time (0.061800
user, 0.000000 system)
     500000000 bytes allocated
     no minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy
smallu1-B)))
     0.317637 secs real time
     0.317530 secs cpu time (0.317530 user, 0.000000 system)
     8 collections accounting for 0.049501 secs real time (0.049480
user, 0.000000 system)
     420000000 bytes allocated
     no minor faults
     no major faults
(time (do ((i 0 (fx+ i 1))) ((fx= i smalliterations)) (array-copy
smallu8-B)))
     0.142781 secs real time
     0.142688 secs cpu time (0.142688 user, 0.000000 system)
     7 collections accounting for 0.043319 secs real time (0.043273
user, 0.000000 system)
     360000000 bytes allocated
     no minor faults
     no major faults
"/home/lucier/lang/scheme/srfi-231/srfi-231-temp/time-arrays.o8"