Did you run each one before timing them, to make sure you’re not timing the compilation?
-s > On Dec 1, 2015, at 11:07 PM, Jorge Johnson <[email protected]> wrote: > > Hi, > I made my first julia function. > I build two functional identical functions, the first one using types and the > second one without types. > > I was expecting the typed function to be more efficient in time and memory > than the untyped one. > however, I was surprised. The untyped function runs very fast and with less > memory. > > here the code an times: > > #TYPED > function HowManyNucleotides(dnaSequenceFile::Base.ASCIIString) > Tuple{Int,Int,Int,Int} > nucA::Int = 0 > nucG::Int = 0 > nucC::Int = 0 > nucT::Int = 0 > nucleotyde::Char = 0 > f = open(dnaSequenceFile) > while (!eof(f)) > nucleotyde = read(f,Char) > if isAdenine(nucleotyde) > nucA+=1 > elseif isGuanine(nucleotyde) > nucG+=1 > elseif isCytosine(nucleotyde) > nucC+=1 > elseif isThymine(nucleotyde) > nucT+=1 > end > end > flush(f) > close(f) > [nucA,nucG,nucC,nucT] > end > > > > > > > > #UNTYPED > function HowManyNucleo(dnaSequenceFile) > nucA = 0 > nucG = 0 > nucC = 0 > nucT = 0 > nucleotyde = '.' > f = open(dnaSequenceFile) > while (!eof(f)) > nucleotyde = read(f,Char) > if isAdenine(nucleotyde) > nucA+=1 > elseif isGuanine(nucleotyde) > nucG+=1 > elseif isCytosine(nucleotyde) > nucC+=1 > elseif isThymine(nucleotyde) > nucT+=1 > end > end > flush(f) > close(f) > [nucA,nucG,nucC,nucT] > end > > > > Times of calls are respectively: > > > > #TYPED > > 0.011514 seconds (26.61 k allocations: 974.385 KB) > > > > #UNTYPED > > 0.005221 seconds (4.88 k allocations: 255.773 KB) > > > > I´m confused, because it is supposed typed julia is more fast. > > > > Any Ideas? > > Thank you >
