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

No comments:

Post a Comment