Skip to content

Instantly share code, notes, and snippets.

@gradha gradha/nimspeed.nim
Last active Dec 17, 2015

What would you like to do?
Initial Nimrod implementation of the file reading/scanning problem at
import strutils
proc process(filename: string) =
input: TFile
lineBuf = newString(100)
gcCount = 0
totalBaseCount = 0
input = open(filename)
finally: input.close()
while input.readLine(lineBuf):
if lineBuf[0] != '>':
for letter in lineBuf:
case letter
of 'A':
totalBaseCount += 1
of 'C':
gcCount += 1
totalBaseCount += 1
of 'G':
gcCount += 1
totalBaseCount += 1
of 'T':
totalBaseCount += 1
let gcFraction = gcCount / totalBaseCount
echo formatFloat(gcFraction * 100, ffDecimal, 4)
when isMainModule:

This comment has been minimized.

Copy link
Owner Author

gradha commented May 10, 2013

For comparison, the best of three time mesurements on my machine were:

$ time python 

real    0m11.097s
user    0m9.934s
sys 0m0.333s

$ time ./nimspeed 

real    0m0.931s
user    0m0.823s
sys 0m0.052s

$ time ./gc_cpp 

real    0m0.697s
user    0m0.586s
sys 0m0.085s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.