Woensdag 17 Januarie 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.


















Read more

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

Geen opmerkings nie:

Plaas 'n opmerking