Saturday, January 27, 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.


















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

No comments:

Post a Comment

Related Posts with Thumbnails