Тёмный

Why is Mojo's dictionary slower (!) than Python's? 

EKB PhD
Подписаться 520
Просмотров 4,4 тыс.
50% 1

Seriously, I don't know why. Leave a comment with feedback on my Mojo script.
Take a look at my Mojo script here:
github.com/ekb...
And here's my Python script:
github.com/ekb...
Here's the Mojo language:
www.modular.co...
BTW: I used the Elgato Wave 3 microphone in this video:
www.elgato.com...
Here's a follow-up video in which a hand-written hashmapdict in Mojo (thanks to Maxim Zaks!) that is faster than Python's dictionary:
• Mojo hand-written hash...
#mojolang #python

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 29   
@brendanhansknecht4650
@brendanhansknecht4650 7 месяцев назад
Python actually has a realy optimized dictionary for its constraints (taking untyped keys and values). Mojo will catch up (and should surpass due to static types), but the current dict is new and mostly unoptimized. Also, this should be memory bound instead of compute bound so even in the long term, I would not expect much of a difference.
@ekbphd3200
@ekbphd3200 6 месяцев назад
Yeah, good points. Thanks.
@hyperplano
@hyperplano 7 месяцев назад
In the discord channel I read the current dictionary implementation is not optimized. It's been included to allow developers to experiment more with the language, but it will be optimized in future releases.
@earlkjarbrown3753
@earlkjarbrown3753 7 месяцев назад
Great to hear! Thanks for pointing this out.
@ekbphd3200
@ekbphd3200 6 месяцев назад
Thanks!
@svenmasche
@svenmasche 6 месяцев назад
lmao up until minute 9 i was expecting that you were going to explain it ^^
@ekbphd3200
@ekbphd3200 6 месяцев назад
Sorry. I'm curious to see when they will be able to optimize the native Mojo dictionary. In the meantime, there's a third-party Mojo dictionary that is faster. Take a look at this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-AqDGkIrD9is.htmlsi=xx6_7G-srSQX3KjF
@sillybuttons925
@sillybuttons925 7 месяцев назад
The script does exercise item lookup, looping etc. So seems like a pretty valid comparison. Maybe try the collections.Counter if it's implemented in mojo?
@ekbphd3200
@ekbphd3200 7 месяцев назад
The hashmapdict is quick, as is the compact dict, written by a third party guy: github.com/mzaks/compact-dict ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-AqDGkIrD9is.html
@murithiedwin2182
@murithiedwin2182 4 месяца назад
Mojo official benchmark with python performance needs a comprehensive "mojo feature to python feature" comparison benchmark... We would like then to see where the 35,000X speed up claim came from...
@ekbphd3200
@ekbphd3200 4 месяца назад
Yeah, I think the specific task is important. As a linguist, I use strings a lot, and Python still seems to be faster than Mojo right now. I hope Mojo becomes faster than Python with strings at some point in the future. Thanks for the comment!
@niks660097
@niks660097 4 месяца назад
@@ekbphd3200 The thing is in python is a lot of string operations are handled by pure C code, for example regex is completely done by a FSM in C, that's why regexes in python are faster than java, golang you name it, if the string you are searching on is big enough, in my current company we were planning to move some code from python to golang cause of performance issues, but while profiling, python's string regexes and dict's perf. caught everyone off guard.
@androth1502
@androth1502 6 месяцев назад
my guess would be that the mojo implementation is a quick lazy thing just to get maps in, while python uses a C implementation.
@ekbphd3200
@ekbphd3200 6 месяцев назад
Yeah, I assume that's what's going on.
@androth1502
@androth1502 6 месяцев назад
@@ekbphd3200 still not a good look for them to release something so unoptimized after boldly claiming to be thousands of times faster than python. lol.
@indibarsarkar3936
@indibarsarkar3936 3 месяца назад
Please try splitting the data in half and assigning each halves to a dictionary. Then measure the time taken to copy or interchange elements from one dictionary to another. Maybe the problem is in the file management and not in dictionary!!
@ekbphd3200
@ekbphd3200 3 месяца назад
Mojo's dictionary has increased in performance (when inserting items) with v24.4. I found a 4x increase in speed with a particular linguistic task. Take a watch: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ZpEZ5zMV1Xs.html
@cmdlp4178
@cmdlp4178 4 месяца назад
Maybe in Mojo the Strings are copied and reallocated as new objects, maybe because of the different StringKey type, or maybe (I am not as familiar with Mojo) because Dict stores and owns an own instance of the string, similar to as in C++. There the string and the memory associated with the string is "owned" by e.g. the unordered_map. Maybe you should retry measuring the time, now inserting floating point numbers for examples, that might not be allocated in Mojo.
@ekbphd3200
@ekbphd3200 4 месяца назад
Good idea! I'll give that a try soon.
@jinsongli3128
@jinsongli3128 4 месяца назад
my test with the List also shows mojo is slower than python, not sure if I did anything wrong.
@ekbphd3200
@ekbphd3200 4 месяца назад
Thanks for that info! Yeah, I assume that at some point Mojo will be faster than Python with most tasks but that’s not the case yet with the linguistic tasks I do most often.
@pe6649
@pe6649 7 месяцев назад
Sorry, but the answer is mostly: It does simply not make sense to do benchmark comparisons with a language or tool under development. Mojo is under development. It is not at all astounding, what you found out. To me it is more astounding that you are surprised. Performance is always about details! Simple expectations like x is faster than y fail VERY often when measured. Take the various steps to make Python faster we absolved in the last decade and more: For exampe- In Python 3.11 at first JIT compiling was added. You can fasten something up, but it is not a nobrainer, and further optimizations are needed and will come. I believe Mojo will do a good job finally. But be a bit more patient. Especially Mojo will shine in optimizing for new hardware architectures. If you just want fast Python, use Numba or Nuitka..
@earlkjarbrown3753
@earlkjarbrown3753 7 месяцев назад
Yeah, good points. I've enjoyed watching Mojo as it's being developed and assume it will be smokingly fast in comparison to Python in nearly all applications at some point in the future.
@ekbphd3200
@ekbphd3200 6 месяцев назад
Thanks!
@talhatahir4931
@talhatahir4931 4 месяца назад
lol!!! Those mojicians claim that they are 60k times faster than python and we can't even show the truth?
@ekbphd3200
@ekbphd3200 4 месяца назад
@@talhatahir4931 Yeah, I think it depends on the benchmark task that is used. As a linguist, I'm interested in processing strings.
@NoX-512
@NoX-512 2 месяца назад
@@talhatahir4931 The 68K claim was using Mojo’s SIMD types in a Mandelbrot function.
Далее
Typed dictionaries in Julia are faster
7:34
An introduction to Mojo (for Python developers)
15:21
НИКИТА ПОДСТАВИЛ ДЖОНИ 😡
01:00
Просмотров 132 тыс.
WHICH SODA CAN FLY THE HIGHEST?
00:48
Просмотров 8 млн
Choosing Your Language: Python or Mojo?
14:33
Просмотров 116 тыс.
How much faster has Mojo's dictionary gotten?
7:40
Просмотров 4,6 тыс.
The Best Package to Plot in Julia
6:02
Просмотров 8 тыс.
Mojo Is FASTER Than Rust
19:22
Просмотров 115 тыс.
5 Useful Python Decorators (ft. Carberra)
14:34
Просмотров 103 тыс.
My 10 “Clean” Code Principles (Start These Now)
15:12
Is This Language Replacing Python?!
14:11
Просмотров 118 тыс.
[UPDATE] Mojo Is Faster Than Rust - Mojo Explains More
52:09