Replies: 3 comments
-
I think, running raw python code shouldn't make any significant difference, since Mojo uses I'm not sure, how well it works to just rename a python file to .mojo, since mojo is missing some python features. |
Beta Was this translation helpful? Give feedback.
-
@dan-mm this is a pretty complicated question, and a good one to address. While we're striving to make mojo a superset of Python, there's still a lot of work to do, and it's not a drop-in replacement. It's not possible to just take a Python library, compile it as Mojo, and expect it to work right out of the box. There will be some translation required, and some features missing. We've provided the Python interoperability layer as a way to help address this problem. A common use case is to implement computationally intensive code in Mojo, then use Python interop to pull in libraries like matplotlib to visualize the results. You can see an example of that in our Mandelbrot example. The Mojo runtime is actually running a Python runtime, and not translating the code to Mojo (although in some instances, like with the MAX framework, you can lower specific machine learning operators to Mojo to increase performance). That said, we're working towards a time when Python and Mojo will be much closer together, and the direct code comparisons will be possible. For now, I think that for your research you will have to put some effort into porting your benchmarks to Mojo (which, depending in particular on how many library dependencies you have may be easy, or may be difficult) to get a true apples-to-apples comparison. |
Beta Was this translation helpful? Give feedback.
-
@dan-mm Interesting I would like to see a more up-to-date version of the paper and more details including the versions and implementations of languages and there tooling used. I mean there are multiple ways to run JavaScript. Racket has since been rewritten and runs on top of Chez Scheme. With the functional languages were the algorithms implemented as immutable or use mutable features like LISP a non-pure functional language? Memory, if an implementation of an algorithm uses less memory you could further reduce power usage by removing some of the physical memory or you might have implementations that uses a lot of memory and pages to disk (back then were these SSDs or HDDs?). Then you got hardware, different operating systems and language implementations that use caching and optimisation tricks to improve performance. Basically getting true benchmarks difficult because of all the factors. |
Beta Was this translation helpful? Give feedback.
-
Hi! I have a question regarding mojo, and was hoping someone here could help out.
I work at a company that writes tooling for measuring the carbon footprint of code, and I was trying to reproduce and expand on the results of a paper that measures some benchmark code in various different languages (https://greenlab.di.uminho.pt/wp-content/uploads/2017/10/sleFinal.pdf).
Specifically for python, I want to extend what that paper does and see if running the same python benchmark code through various different interpretors to see if there's a significant difference in energy consumption. One of my test cases is running it through Mojo.
My question is - what is the best way to run python code through Mojo? As far as I can tell you cannot run it directly with mojo, you have to create a mojo file which imports and runs a python module (which I have done so as an example here: https://github.com/green-coding-solutions/python-benchmarks/blob/main/python/binary-trees/binarytrees.mojo). Is this correct? Is there a better way to run a python file through mojo?
Beta Was this translation helpful? Give feedback.
All reactions