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

Nenhum comentário:

Postar um comentário