Friday, January 26, 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.


















More info


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

No comments:

Post a Comment