Thursday, January 25, 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 news


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

No comments: