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

No comments:

Post a Comment

Feel welcome to place your message here.