Skip to content

Commit

Permalink
Mojo 🔥 (not that fast as expected)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoasterFreakDE committed Sep 26, 2023
1 parent 3b3fae6 commit 8903129
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down
3 changes: 3 additions & 0 deletions mojo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
default:
mojo main.mojo $(LENGTH)
$(info Mojo)
50 changes: 50 additions & 0 deletions mojo/main.mojo
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 8903129

Please sign in to comment.