Basic HTML

Tuesday, January 23, 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 links

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

No comments:

Post a Comment