Skip to content

Instantly share code, notes, and snippets.

@samth
Created June 5, 2012 12:27
Show Gist options
  • Save samth/2874695 to your computer and use it in GitHub Desktop.
Save samth/2874695 to your computer and use it in GitHub Desktop.
Chris Leary's benchmark in Racket
import random
import sys
def main():
if len(sys.argv) != 2:
print >> sys.stderr, "Usage: %s <elem_count>" % sys.argv[0]
exit(-1)
count = int(sys.argv[1])
random.seed()
with open('vec_gen.out', 'w') as file:
for i in xrange(count):
r = random.getrandbits(31)
file.write('%d\n' % r)
if __name__ == '__main__':
main()
#lang racket/base
;; see http://blog.cdleary.com/2012/06/simple-selfish-and-unscientific-shootout/ for source
(require racket/cmdline)
(define MAXINT 2147483647)
(define (go n)
(call-with-output-file "vec-gen.out" #:exists 'replace
(λ (o)
(for ([i (in-range n)])
(write (random MAXINT) o) (newline o)))))
(module+ main (command-line #:args (n) (go n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment