Created
June 5, 2012 12:27
-
-
Save samth/2874695 to your computer and use it in GitHub Desktop.
Chris Leary's benchmark in Racket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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