Sunday, January 21, 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.



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

$ 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 (0x00007ffd94917000) => /lib/x86_64-linux-gnu/ (0x00007fe899cb1000) => /lib/x86_64-linux-gnu/ (0x00007fe899a00000) => /lib/x86_64-linux-gnu/ (0x00007fe899921000) => /lib/x86_64-linux-gnu/ (0x00007fe899c91000) => /lib/x86_64-linux-gnu/ (0x00007fe899740000)

/lib64/ (0x00007fe899d2c000)

$ ldd -d rust_benchmark (0x00007ffde67b7000) => /lib/x86_64-linux-gnu/ (0x00007f8b3881b000) => /lib/x86_64-linux-gnu/ (0x00007f8b3863a000)

/lib64/ (0x00007f8b388ae000)

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



Steps until libc write:



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

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

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


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.

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() 


Related links

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