performance measurements

Each table row shows performance measurements for this Lisp SBCL program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
250,0003.883.8850,208847  1% 1% 0% 100%
2,500,000Bad Output  847   

Read the ↓ make, command line, and program output logs to see how this program was run.

Read k-nucleotide benchmark to see what this program should do.

 notes

This is SBCL 1.2.0, an implementation of ANSI Common Lisp.

 k-nucleotide Lisp SBCL program source code

;;   The Computer Language Benchmarks Game
;;   http://benchmarksgame.alioth.debian.org/
;;   contributed by James McIlree
;;   Modified by Juho Snellman 2005-11-19
;;     * About 50% speedup on both SBCL and CMUCL
;;     * Use SIMPLE-BASE-STRINGs instead of (SIMPLE-ARRAY CHARACTER) for
;;       lower memory use on Unicode SBCL
;;     * Declare the type of SEQUENCE in ACCUMULATE-FREQUENCIES

(defun read-data (stream)
  (let ((data (make-array 0 :element-type 'base-char :adjustable t :fill-pointer 0)))
    (do ((line (read-line stream nil 'eof) (read-line stream nil 'eof)))
        ((or (eq line 'eof) (string= ">THREE" line :start2 0 :end2 6))))
    (do ((line (read-line stream nil 'eof) (read-line stream nil 'eof)))
        ((or (eq line 'eof) (char= (schar line 0) #\>)))
      (if (not (char= (schar line 0) #\;))
          (dotimes (char-index (length line))
            (vector-push-extend (char-upcase (the base-char (schar line char-index))) data))))
    (coerce data 'simple-base-string)))

(defun accumulate-frequencies (hashmap sequence offset fragment-length)
  (declare (type (integer 0 18) fragment-length)
           (fixnum offset)
           (type (simple-base-string) sequence))
  (let ((last-sequence-index (- (length sequence) fragment-length)))
    (do ((start offset (+ start fragment-length)))
        ((> start last-sequence-index))
      (let ((fragment (subseq sequence start (+ start fragment-length))))
        (setf (gethash fragment hashmap) (1+ (the (integer 0 999999) (gethash fragment hashmap 0))))))))

(defun calculate-frequencies (sequence fragment-length)
  (declare (type (integer 0 18) fragment-length))
  (let ((hashmap (make-hash-table :test #'equal)))
    (dotimes (offset fragment-length)
      (accumulate-frequencies hashmap sequence offset fragment-length))
    hashmap))

(defun write-frequencies (sequence length)
  (let ((sorted-frequencies)
        (sum 0))
    (declare (fixnum sum))
    (maphash #'(lambda (k v)
                 (setf sum (+ sum (the fixnum v)))
                 (setf sorted-frequencies (cons (cons k v) sorted-frequencies))) (calculate-frequencies sequence length))
    (setf sorted-frequencies (sort sorted-frequencies #'(lambda (v1 v2)
                                                          (cond ((> (the (integer 0 999999) (cdr v1)) (the (integer 0 999999) (cdr v2))) t)
                                                                ((< (the (integer 0 999999) (cdr v1)) (the (integer 0 999999) (cdr v2))) nil)
                                                                (t (string< (car v1) (car v2)))))))
    (dolist (entry sorted-frequencies) (format t "~A ~,3F~%" (car entry) (* (/ (the (integer 0 999999) (cdr entry)) sum) 100.0)))
    (terpri)))

;;
;; Delete this before including in the shootout, test method only.
;;
;;(defun test-main (filename)
;;  (with-open-file (stream filename)
;;    (let ((sequence (read-data stream)))
;;      (declare (type (simple-array * *) sequence))
;;      (dolist (entry '(1 2)) (write-frequencies sequence entry))
;;      (dolist (entry '("GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT"))
;;        (declare (type (simple-array * *) entry))
;;        (format t "~A~C~A~%" (gethash entry (calculate-frequencies sequence (length entry)) 0) #\Tab entry)))))

(defun main ()
  (let ((sequence (read-data *standard-input*)))
    (declare (type (simple-array * *) sequence))
    (dolist (entry '(1 2)) (write-frequencies sequence entry))
    (dolist (entry '("GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT"))
      (declare (type (simple-array * *) entry))
      (format t "~A~C~A~%"
              (gethash entry (calculate-frequencies sequence (length entry)) 0)
              #\Tab entry))))

 make, command-line, and program output logs

Sat, 31 May 2014 04:57:59 GMT

MAKE:
cp: ‘knucleotide.sbcl’ and ‘./knucleotide.sbcl’ are the same file
SBCL built with: /usr/local/bin/sbcl --userinit /dev/null --batch --eval '(load "knucleotide.sbcl_compile")'
### START knucleotide.sbcl_compile
(handler-bind ((sb-ext:defconstant-uneql      (lambda (c) (abort c))))      (load (compile-file "knucleotide.sbcl" ))) (save-lisp-and-die "sbcl.core" :purify t)
### END knucleotide.sbcl_compile

; compiling file "/home/dunham/benchmarksgame/bench/knucleotide/knucleotide.sbcl" (written 24 JAN 2013 02:01:15 PM):
; compiling (DEFUN READ-DATA ...)
; compiling (DEFUN ACCUMULATE-FREQUENCIES ...)
; compiling (DEFUN CALCULATE-FREQUENCIES ...)
; compiling (DEFUN WRITE-FREQUENCIES ...)
; compiling (DEFUN MAIN ...)

; /home/dunham/benchmarksgame_onecore/knucleotide/tmp/knucleotide.fasl written
; compilation finished in 0:00:00.051
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into sbcl.core:
writing 3528 bytes from the read-only space at 0x0x1000000
writing 2240 bytes from the static space at 0x0x1100000
writing 30208000 bytes from the dynamic space at 0x0x9000000
done]
### START knucleotide.sbcl_run
(main) (quit)
### END knucleotide.sbcl_run

0.69s to complete and log all make actions

COMMAND LINE:
/usr/local/bin/sbcl   --noinform --core sbcl.core --userinit /dev/null --load knucleotide.sbcl_run 0 < knucleotide-input2500000.txt

UNEXPECTED OUTPUT 

0a1,27
> A 30.297
> T 30.151
> C 19.798
> G 19.755
> 
> AA 9.177
> TA 9.133
> AT 9.131
> TT 9.091
> CA 6.002
> AC 6.001
> AG 5.987
> GA 5.984
> CT 5.971
> TC 5.971
> GT 5.957
> TG 5.956
> CC 3.917
> GC 3.910
> CG 3.909
> GG 3.903
> 
> 147166	GGT
> 44658	GGTA
> 4736	GGTATT
> 89	GGTATTTTAATT
> 89	GGTATTTTAATTTATAGT

PROGRAM OUTPUT:


debugger invoked on a TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {ACD29F1}>:
  The value 1000000 is not of type (MOD 1000000).

Revised BSD license

  Home   Conclusions   License   Play