/mobile Handheld Friendly website
x64 Ubuntu : Intel® Q6600® quad-core |
Each table row shows performance measurements for this Racket program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 250,000 | Bad Output | 842 |
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.
Welcome to Racket v5.3.4.
#lang racket/base ;; The Computer Language Shootout ;; http://benchmarksgame.alioth.debian.org/ (require racket/future racket/require (for-syntax racket/base) racket/port racket/place (filtered-in (λ (name) (regexp-replace #rx"unsafe-" name "")) racket/unsafe/ops)) (define (all-counts len dna) (define table (make-hasheq)) (define seq (make-bytes len)) (for ([s (in-range (- (bytes-length dna) len) -1 -1)]) (bytes-copy! seq 0 dna s (+ s len)) (define key (string->symbol (bytes->string/utf-8 seq))) (define cnt (hash-ref table key 0)) (hash-set! table key (add1 cnt))) table) (define (write-freqs table port) (define content (hash-map table cons)) (define total (exact->inexact (apply + (map cdr content)))) (for ([a (sort content > #:key cdr)]) (fprintf port "~a ~a\n" (car a) (real->decimal-string (fl* 100. (fl/ (fx->fl (cdr a)) total)) 3)))) (define (write-one-freq table key port) (define cnt (hash-ref table key 0)) (fprintf port "~a\t~a\n" cnt key)) (define-syntax-rule (at-place (var ...) body ...) (let () (define p (place ch (define var (place-channel-get ch)) ... (place-channel-put ch (let () body ...)))) (place-channel-put p var) ... p)) (define (main . _) (define dna-shared (let () (define in (current-input-port)) ;; Skip to ">THREE ..." (regexp-match #rx#"(?m:^>THREE.*$)" in) (define s (open-output-bytes)) ;; Copy everything but newlines to s: (for ([l (in-bytes-lines in)]) (write-bytes l s)) ;; Extract the bytes from s: (define dna (get-output-bytes s)) (define sb (make-shared-bytes (bytes-length dna))) (for ([i (in-range (bytes-length dna))]) (bytes-set! sb i (fx- (bytes-ref dna i) 32))) sb)) (define l (append ;; 1/2-nucleotide counts: (for/list ([i '(1 2)]) (at-place (i dna-shared) (define pr (open-output-bytes)) (write-freqs (all-counts i dna-shared) pr) (newline pr) (get-output-bytes pr))) ;; Specific sequences: (for/list ([seq '("GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT")]) (at-place (seq dna-shared) (define pr (open-output-bytes)) (write-one-freq (all-counts (string-length seq) dna-shared) (string->symbol seq) pr) (get-output-bytes pr))))) (for ([p l]) (write-bytes (place-channel-get p)))) (provide main)
Sat, 11 May 2013 16:29:54 GMT COMMAND LINE: /usr/local/src/racket-5.3.4/bin/racket knucleotide.racket-2.racket 0 < knucleotide-input250000.txt UNEXPECTED OUTPUT 0a1,27 > A 30.298 > T 30.157 > C 19.793 > G 19.752 > > AA 9.177 > TA 9.137 > AT 9.136 > TT 9.094 > AC 6.000 > CA 5.999 > GA 5.986 > AG 5.985 > TC 5.970 > CT 5.970 > GT 5.957 > TG 5.956 > CC 3.915 > CG 3.910 > GC 3.908 > GG 3.902 > > 14717 GGT > 4463 GGTA > 472 GGTATT > 9 GGTATTTTAATT > 9 GGTATTTTAATTTATAGT PROGRAM OUTPUT: