diff --git a/Makefile b/Makefile index 0c017a6..129733e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -LANGUAGES = c cpp erlang go java js perl python rust haskell csharp coffeescript lua +LANGUAGES = c cpp erlang go java js perl python rust haskell csharp coffeescript lua mojo LENGTH = 13 default: $(LANGUAGES) RUN diff --git a/README.md b/README.md index 998606d..1a2b345 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Note that the results are not 100% accurate, because the test is run on a shared | Java | 17ms | 50ms | 158ms | 599ms | 2.703s | / | / | Win11 / i9-12900KF | | JavaScript | 58ms | 225ms | 894ms | 3.467s | 14.543s | / | / | Win11 / i9-12900KF | | C# | 98ms | 333ms | 1.207s | 4.588s | 18.205s | 72.196s | 265.764s | Win11 / i9-12900KF | +| Mojo | 319ms | 1.289s | 5.090s | 20.944s | 83.584s | / | / | Win11 / i9-12900KF (WSL Ubuntu) | | Erlang | 375ms | 1.607s | 6.397s | 25.117s | 105.529s | / | / | Win11 / i9-12900KF | | php | 561ms | 2.164s | 8.892s | 35.038s | 140.391s | / | / | Win11 / i9-12900KF | | Perl | 643ms | 2.568s | 10.182s | 41.137s | 169.598s | / | / | Win11 / i9-12900KF | @@ -163,6 +164,16 @@ Note that the results are not 100% accurate, because the test is run on a shared | 14 | 99.665s | Win11 / i9-12900KF | | 15 | 414.169s | Win11 / i9-12900KF | +### Mojo + +| Kmer | Duration | (Optional) Runtime Env / OS | +|------|----------|-----------------------------| +| 11 | 319ms | Win11 / i9-12900KF (WSL Ubuntu) | +| 12 | 1.289s | Win11 / i9-12900KF (WSL Ubuntu) | +| 13 | 5.090s | Win11 / i9-12900KF (WSL Ubuntu) | +| 14 | 20.944s | Win11 / i9-12900KF (WSL Ubuntu) | +| 15 | 83.584s | Win11 / i9-12900KF (WSL Ubuntu) | + ### Rust | Kmer | Duration | (Optional) Runtime Env / OS | diff --git a/mojo/Makefile b/mojo/Makefile new file mode 100644 index 0000000..101735b --- /dev/null +++ b/mojo/Makefile @@ -0,0 +1,3 @@ +default: + mojo main.mojo $(LENGTH) + $(info Mojo) \ No newline at end of file diff --git a/mojo/main.mojo b/mojo/main.mojo new file mode 100644 index 0000000..35c73c4 --- /dev/null +++ b/mojo/main.mojo @@ -0,0 +1,50 @@ +import time +from sys import argv + +fn convert(c: String) -> String: + if c == 'A': + return 'C' + if c == 'C': + return 'G' + if c == 'G': + return 'T' + if c == 'T': + return 'A' + return '' + +fn stringToInt(s: String) -> Int: + var res: Int = 0 + try: + res = atol(s) + except: + res = 0 + return res + +fn main(): + let time_start = time.now() + let opt: String = "ACGT" + let opt_len: Int = len(opt) + var s: String = "" + var s_last: String = "" + let len_str: Int = stringToInt(argv()[1]) + + for i in range(len_str): + s += opt[0] + + for i in range(len_str): + s_last += opt[opt_len - 1] + + var counter: Int = 1 + while(s != s_last): + counter += 1 + for i in range(len_str): + if (s[i] == opt[opt_len - 1]): + s = s[:i] + convert(s[i]) + s[i+1:] + else: + s = s[:i] + convert(s[i]) + s[i+1:] + break + + # You can uncomment the next line to see all k-mers. + # print(s) + let time_elapsed = time.now() - time_start + print("Number of generated k-mers:", counter, "- took", time_elapsed / 1000000, "ms") \ No newline at end of file