Sunday, January 28, 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 word


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

No comments:

Post a Comment