I'd been sitting on a Mojo Playground invite for a few weeks but hadn't done much with it beyond looking at the intro. Then I received a mail about a new interactive tutorial, so I thought I'd give it a go. And, as it happens, the algorithm he was demo-ing was one I'd just been using in my hand-rolled Python Machine Learning (ML) example that formed the basis for my first proper Rust program. Also, I'd just spent some time going through a Python ML tutorial, so it arrived at the right time for me to take interest.
In brief, the example calculates and times the Euclidean Distance between two vectors in Python and then in Mojo and compares the two (there are a few steps in between, such a adding NumPy and so on) but ultimately he ends with this.
Our Mojo code execution time dropped down to ~13 ms. That’s almost 2x faster than the NumPy which is implemented in C/C++ and 60x faster than the pure Python implementation. Let’s take a look at the Python and Mojo code side by side so you can appreciate how little you had to change the code to see the performance improvements.
So, this was just from adding declarations and strong typing.
I got the same results when I worked through it myself.
The 60x figure was interesting because it was roughly how much faster my own Rust ML program was compared to Python.
Anyway, this suggests that Mojo is at least comparable to C/C++/Rust. Of course, the marketing to date claims potentially much higher speedups. And I do recall seeing a video example which took it up to a much larger factor - hundreds I think - but not 35K or whatever.
I think what I'll try and do next is try my Python ML in the playground and Mojo-ise it. Though I'm not sure whether they let you upload csv files for input.
The playground seemed to be about twice as fast as my dev box when I ran their Python locally. So I should be able to estimate how it compares to Rust. 
Update: My Python was running an old Anaconda version. Upgrading to 3.11.1 64-bit speeded it up from 22s to 13s. The Rust is at 0.3s. So 43x.
It looks like I should be able to try my example in the Playground and Mojo-ise it. But that will likely be a task for next week now when I have time.