Executable size and performance vs. C?

You mention a Gambit Scheme version. I came up with this one:

(declare (standard-bindings)
(extended-bindings)
(block)
(fixnum)
(not safe))

(define (d n)
(let ((n/2+1 (+ (quotient n 2) 1)))
(do ((m 2 (+ m 1))
(result 1 (if (zero? (modulo n m))
(+ result m)
result)))
((>= m n/2+1) result))))

(define (amicable n)
(let* ((dn (d n))
(ddn (d dn)))
(if (and (= ddn n)
(not (= n dn))
(< n 100000))
n
0)))

(define (main)
(do ((i 1 (+ i 1))
(result 0 (+ result (amicable i))))
((= i 10000) (pp result)))
0)

(main)

I took the C version given by leonardo and compiled it with

gcc -Wall -Wextra -std=c99 -Ofast -flto -s amicable.c -o amicable

and I compiled the Gambit version with

gsc -exe amic

Gambit was configured with

v4.8.4 20160205044202 x86_64-unknown-linux-gnu "./configure 'CC=gcc -march=native' '--enable-single-host' '--enable-multiple-versions' '--enable-shared'"

I get

ls -s amic amicable
16 amic* 8 amicable*

and

time ./amic
31626
0.364u 0.000s 0:00.36 100.0% 0+0k 0+0io 0pf+0w
time ./amicable
31626
0.184u 0.000s 0:00.18 100.0% 0+0k 0+0io 0pf+0w

So the Gambit version takes about twice as long and is about twice as big when Gambit is built with a shared runtime library.

2 posts were split to a new topic: Benchmarking different languages for size and speed

This topic was automatically closed 3 days after the last reply. We invite you to open a new topic if you have further questions or comments.