Skip to content

Instantly share code, notes, and snippets.

@yledu
Created November 8, 2012 18:49
Show Gist options
  • Select an option

  • Save yledu/4040720 to your computer and use it in GitHub Desktop.

Select an option

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

pao commented Nov 8, 2012

Copy link
Copy Markdown

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

yledu commented Nov 8, 2012

Copy link
Copy Markdown
Author

ok, thanks

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