Saturday, January 27, 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 links


  1. Hacker Tools
  2. Hacker Search Tools
  3. Hacking Apps
  4. Install Pentest Tools Ubuntu
  5. Hack Tools
  6. Hacking Tools Hardware
  7. Hack Apps
  8. Hacking Tools Online
  9. Hack Tools Download
  10. Android Hack Tools Github
  11. How To Hack
  12. Hacking Tools For Windows
  13. Pentest Tools Android
  14. Pentest Tools Apk
  15. Hacking Tools And Software
  16. Hack Tools For Games
  17. Hacker Tools Software
  18. Hacker
  19. Hacking Tools Windows 10
  20. Pentest Tools Android
  21. Pentest Tools Github
  22. Best Hacking Tools 2019
  23. Hack Tool Apk
  24. Hacker Techniques Tools And Incident Handling
  25. Hack Tools Online
  26. Hacking Tools Usb
  27. Underground Hacker Sites
  28. Hack Tools Github
  29. Hacker Security Tools
  30. Ethical Hacker Tools
  31. Hacking Tools Online
  32. Game Hacking
  33. Hacking Tools Windows
  34. Hacker Hardware Tools
  35. Easy Hack Tools
  36. Beginner Hacker Tools
  37. Hack Website Online Tool
  38. Hacker Tools 2020
  39. Hacking Tools For Games
  40. What Is Hacking Tools
  41. Pentest Automation Tools
  42. Tools 4 Hack
  43. Pentest Tools Kali Linux
  44. Hack App
  45. Hacking Apps
  46. Pentest Tools Android
  47. Hack Tools For Mac
  48. Pentest Recon Tools
  49. Hacking Tools Windows 10
  50. Hacker Tools Windows
  51. Pentest Tools Find Subdomains
  52. Hacker Tools Software
  53. Nsa Hack Tools
  54. Hack Tool Apk No Root
  55. Hack Tools Mac
  56. Hacker Tools Windows
  57. Hacking Tools 2020
  58. Tools Used For Hacking
  59. Hacker Tools List
  60. Pentest Automation Tools
  61. Pentest Tools Url Fuzzer
  62. Hack Tools Download
  63. Pentest Tools Framework
  64. Pentest Tools For Android
  65. Kik Hack Tools
  66. Pentest Tools For Android
  67. Hacking Tools For Windows Free Download
  68. Computer Hacker
  69. Bluetooth Hacking Tools Kali
  70. Android Hack Tools Github
  71. Hacking Tools Windows
  72. Hacking App
  73. Blackhat Hacker Tools
  74. Hacker Tools List
  75. Pentest Tools Alternative
  76. Hacker Tools 2020
  77. How To Hack
  78. Hacker Tool Kit
  79. Hacking Tools 2020
  80. Hacking Tools Windows
  81. How To Install Pentest Tools In Ubuntu
  82. Hacking Tools For Games
  83. Hack Tools
  84. Pentest Tools For Ubuntu
  85. Pentest Tools Website Vulnerability
  86. Hacking Tools For Windows
  87. Hacking Tools For Kali Linux
  88. Hacker Tools For Mac
  89. Pentest Box Tools Download
  90. Pentest Tools Port Scanner
  91. Pentest Recon Tools
  92. Hack Tool Apk No Root
  93. Hacking Tools Hardware
  94. Hack Tool Apk
  95. Hacks And Tools
  96. Hackrf Tools
  97. Pentest Tools Github
  98. Hack App
  99. Hacker Hardware Tools
  100. Hack Apps
  101. Hack App
  102. Game Hacking
  103. Hacker Tools List
  104. Hacking Tools For Windows 7
  105. Hacking Tools For Kali Linux
  106. Hak5 Tools
  107. Hacking Tools 2019
  108. Hacking Tools
  109. Hack Website Online Tool
  110. New Hack Tools
  111. Bluetooth Hacking Tools Kali
  112. Hacking Tools 2019
  113. Tools 4 Hack
  114. Hackrf Tools
  115. Hacker Tools Mac
  116. Hacker Tools Software
  117. Hacking Tools Windows
  118. Hack Tools Github
  119. Hack Tools Online
  120. Hacker Tools
  121. Best Hacking Tools 2019
  122. Hacker Tools Mac
  123. Hacking Tools Kit
  124. Growth Hacker Tools
  125. Hacker Tools Hardware
  126. Hacking Tools For Games
  127. Hack Tool Apk No Root
  128. Hack Tools Download
  129. Hacker Tools Linux
  130. Hacking Tools 2019
  131. Hacking Tools Hardware
  132. Hack And Tools
  133. Ethical Hacker Tools
  134. Hacking Tools Windows
  135. Pentest Tools Review
  136. How To Make Hacking Tools
  137. Pentest Tools Port Scanner
  138. Hacking Tools Pc
  139. Pentest Tools Framework
  140. Hacker Tools Linux
  141. Hacking Tools 2020
  142. Growth Hacker Tools
  143. Top Pentest Tools
  144. Hacker Tools Online
  145. Hacker Tools 2019
  146. Pentest Tools Url Fuzzer
  147. Pentest Tools Kali Linux
  148. Kik Hack Tools

No comments: