-
How is it possible and how to optimize the code? from Time import now
mojo_t1 = now()
from PythonInterface import Python
let builtins = Python.import_module("builtins")
let x = builtins.str('Hello Mojo')
let slicing = builtins.slice(5)
builtins.print(x[slicing])
mojo_t2 = now()
print(mojo_t2 - mojo_t1) Execution time = 77708 %%python
import time
start = time.time()
b = "Hello Mojo"
print(b[0:5])
end = time.time()
print(end - start) Execution time = 3.0517578125e-05 |
Beta Was this translation helpful? Give feedback.
Answered by
mfranzon
May 15, 2023
Replies: 1 comment 1 reply
-
You can use the built-in from String import String
from Time import now
mojo_t1 = now()
print(String("Hello Mojo")[0:5])
mojo_t2 = now()
print(mojo_t2 - mojo_t1) # 18128ns |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
survuvi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the built-in
String
struct instead of using python functions: