Last active
March 6, 2019 18:35
-
-
Save samuell/5589994 to your computer and use it in GitHub Desktop.
Table-optimized D version of this benchmark: http://saml.rilspace.org/moar-languagez-gc-content-in-python-d-fpc-c-and-c
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 std.stdio; | |
import std.string; | |
import std.algorithm; | |
void main() { | |
File file = File("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r"); | |
int countat[256]; | |
int countgc[256]; | |
countat['A'] = 1; | |
countat['T'] = 1; | |
countgc['G'] = 1; | |
countgc['C'] = 1; | |
int at = 0; | |
int gc = 0; | |
char[] line; | |
while(file.readln(line)){ | |
if (!startsWith(line, '>')) { | |
foreach (char c; line) { | |
at += countat[c]; | |
gc += countgc[c]; | |
} | |
} | |
} | |
float gcFraction = ( cast(float)gc / cast(float)(at+gc) ); | |
writeln( gcFraction * 100 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment