Skip to content

Instantly share code, notes, and snippets.

@yledu
Created November 8, 2012 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yledu/4040720 to your computer and use it in GitHub Desktop.
Save yledu/4040720 to your computer and use it in GitHub Desktop.
function writeStuff(n)
f=open("data.txt","w")
for el in 1:n
r=randi(Int32)
println(f,r)
end
close(f)
end
N = 1000_000
tic();writeStuff(N);toc()
import random
import sys
def writeStuff(n):
random.seed()
with open('data.txt', 'w') as file:
for i in xrange(n):
r = random.getrandbits(31)
print >> file, r
file.close()
N = 1000000
writeStuff(N)
function writeStuff(n)
f=open("data.txt","w")
for el in 1:n
r="12"
println(f,r)
end
close(f)
end
N = 1000_000
tic();writeStuff(N);toc()
import sys
def writeStuff(n):
with open('data.txt', 'w') as file:
for i in xrange(n):
r = "12"
print >> file, r
N = 1000000
writeStuff(N)
@pao
Copy link

pao commented Nov 8, 2012

The close() at the end of the with block is not needed, and indeed not idiomatic, as it's implied by leaving the context of the with block.

@yledu
Copy link
Author

yledu commented Nov 8, 2012

ok, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment