Friday, January 19, 2024

Mojo Vs Rust, Basic Test And Binary Perspective.

Hello, In first place I'm not going to do an algorithmic benchmark, just a simple loop + print test and some checks on the generated binaries.

The system is a Debian12 Linux and the architecture is: x86 64bits.



Rust

Mojo


Mojo don't allow .py extension it has to be .mojo so no default nvim highlighting ...


$ mojo build mojo_benchmark.mojo

$ time ./mojo_benchmark

...

real 0m0.342s

user 0m0.080s

sys 0m0.252s



$ rustc rust_benchmark.rs

$ time ./rust_benchmark

...

real 0m0.107s

user 0m0.012s

sys 0m0.049s


I noticed a speed increase using fish shell instead of bash but could be the environment variable stack overload.


So in this specific test rust is much faster. And also the compiler suggests using _ instead i, that mojo compiler doesn't.

The rust binary is bigger, but is because the allocator is embedded:

-rwxr-xr-x 1 sha0 sha0 1063352 Jan 10 08:55 mojo_benchmark

-rwxr-xr-x 1 sha0 sha0 4632872 Jan 10 08:57 rust_benchmark


But Look this, mojo uses libstdc++ and libc  and rust only uses libc.

$ ldd -d mojo_benchmark

linux-vdso.so.1 (0x00007ffd94917000)

libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007fe899cb1000)

libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe899a00000)

libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe899921000)

libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe899c91000)

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe899740000)

/lib64/ld-linux-x86-64.so.2 (0x00007fe899d2c000)


$ ldd -d rust_benchmark

linux-vdso.so.1 (0x00007ffde67b7000)

libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8b3881b000)

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8b3863a000)

/lib64/ld-linux-x86-64.so.2 (0x00007f8b388ae000)



Lets check the binary.
All the python non used built-ins are written to the binary, so does rust in this case.

mojo

rust




Steps until libc write:

Mojo



Rust


Ok wait, rustc like cargo by default is on debug-mode which is the slower version, the way to do cargo --release which is much faster is  rustc -O rust_benchmark.rs

real 0m0.107s
user 0m0.005s
sys 0m0.056s


This simple program don't make profit of the optimizations.


Rust


We reduced from 30 calls to 27.
I'm not going to criticize the number of calls because rust does his magic and result faster.

Mojo only 7 calls but runtime seems slower.

Regarding memory operations, seems that is rust like compiler-time borrow checked.

https://docs.modular.com/mojo/programming-manual.html#behavior-of-destructors


Rust decompiled


Rust disassembled





Mojo decompiled





Mojo disassembled



So we have two things: the crafted assembly speed, and specially the runtime speed.

Looking the Rust assembly, it's writing the string pointer to stack on every iteration which is same pointer in every iteration.

However Mojo loop is more optimized, param and address to call are pre-calculated before the loop.


So Mojo is generating optimized code, but its c++ API seems slower, at least the print() 

Regards.


















Related articles


  1. Pentest Tools Website
  2. Hack App
  3. Hack Tool Apk No Root
  4. Pentest Tools Android
  5. Hacker Tools Online
  6. Top Pentest Tools
  7. Hacker Tools 2019
  8. Hacking Apps
  9. Hack Tools For Windows
  10. Pentest Tools Review
  11. Hacking Tools Kit
  12. Pentest Tools Open Source
  13. Hacker Search Tools
  14. Pentest Tools Github
  15. Tools For Hacker
  16. Nsa Hacker Tools
  17. Hacker Tool Kit
  18. Pentest Tools For Mac
  19. Hack Website Online Tool
  20. Android Hack Tools Github
  21. Hacking Tools Kit
  22. Underground Hacker Sites
  23. Hacking Tools Download
  24. How To Make Hacking Tools
  25. Easy Hack Tools
  26. Hacker Tools Github
  27. Pentest Tools Download
  28. Hack Tools For Ubuntu
  29. Pentest Box Tools Download
  30. Hack Apps
  31. Pentest Tools For Android
  32. Pentest Reporting Tools
  33. Hacking Tools For Kali Linux
  34. Hacker Tools Github
  35. Hack Tools Online
  36. Wifi Hacker Tools For Windows
  37. Tools Used For Hacking
  38. Pentest Tools Tcp Port Scanner
  39. Hack Tools For Games
  40. Install Pentest Tools Ubuntu
  41. Pentest Tools Kali Linux
  42. Top Pentest Tools
  43. Pentest Tools For Android
  44. Computer Hacker
  45. Pentest Tools Website
  46. Hacking Apps
  47. Hacker Tool Kit
  48. Hack Apps
  49. Computer Hacker
  50. Hack Tool Apk No Root
  51. Hack Tools Online
  52. Usb Pentest Tools
  53. Hacking Tools Usb
  54. Pentest Reporting Tools
  55. Pentest Tools For Windows
  56. Hacking Tools 2020
  57. Hacker Tools For Mac
  58. Pentest Tools Review
  59. Pentest Tools Android
  60. Hacker Tools Apk
  61. Hacker Tools Free Download
  62. Hak5 Tools
  63. Hacking Tools Software
  64. Hacking Tools Github
  65. Hack Tools For Games
  66. Hacking Tools Online
  67. What Is Hacking Tools
  68. Hacker
  69. Pentest Tools Url Fuzzer
  70. Pentest Tools Github
  71. Hacking Tools Free Download
  72. Hacker Tools Software
  73. Bluetooth Hacking Tools Kali
  74. Wifi Hacker Tools For Windows
  75. Pentest Tools For Ubuntu
  76. Top Pentest Tools
  77. Hacker Tools Online
  78. Hacking Tools Usb
  79. Pentest Tools Kali Linux
  80. Hack Rom Tools
  81. Pentest Tools Subdomain
  82. Hacker Tools Windows
  83. How To Install Pentest Tools In Ubuntu
  84. Hacking Tools For Windows Free Download
  85. Hacking Tools
  86. Pentest Tools Subdomain
  87. Pentest Tools Website Vulnerability
  88. What Are Hacking Tools
  89. Pentest Tools Bluekeep
  90. Hack Tools Online
  91. Hack Website Online Tool
  92. Pentest Tools Website
  93. Top Pentest Tools
  94. Hacking Tools For Windows Free Download
  95. Hacking Tools For Windows 7
  96. Hack Tools For Games
  97. Hack Rom Tools
  98. How To Hack
  99. What Is Hacking Tools
  100. Hack Tools For Games
  101. What Are Hacking Tools
  102. Pentest Tools Github
  103. Hacker Tools Apk Download
  104. Hacker Tools Apk Download
  105. Top Pentest Tools
  106. Hack Website Online Tool
  107. Hacker Tools Free
  108. Hack And Tools
  109. Hack Tools Mac
  110. Hacking Tools Name
  111. Hacking Tools Name
  112. Hack Tool Apk
  113. Hacker Tools Github

No comments:

Post a Comment