21 ene 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.


















Continue reading

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

No hay comentarios: