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. Hack Tools Mac
  2. Best Pentesting Tools 2018
  3. Hacker Tools Mac
  4. Free Pentest Tools For Windows
  5. Pentest Tools Bluekeep
  6. Pentest Tools Apk
  7. Underground Hacker Sites
  8. Hack Apps
  9. Hacking Tools Name
  10. Hacking Tools Name
  11. Kik Hack Tools
  12. Best Hacking Tools 2020
  13. Hacking App
  14. Hack Tools Online
  15. Hacker Tools Windows
  16. Hacker Tools For Windows
  17. Hacker Tools Hardware
  18. Pentest Tools For Windows
  19. Hacker Tools Github
  20. Hacking Tools For Windows Free Download
  21. Hacker Tools Online
  22. Black Hat Hacker Tools
  23. Hacking Tools For Mac
  24. Pentest Tools Website Vulnerability
  25. Pentest Tools Open Source
  26. Hacking Tools Download
  27. Hackrf Tools
  28. Hack Tools For Games
  29. How To Hack
  30. Pentest Tools Find Subdomains
  31. Pentest Tools For Mac
  32. Hacking Tools For Beginners
  33. What Is Hacking Tools
  34. Blackhat Hacker Tools
  35. Pentest Tools Website Vulnerability
  36. Hacking Tools For Windows Free Download
  37. Hacker Tools Free Download
  38. New Hacker Tools
  39. Hacker Tools For Pc
  40. Game Hacking
  41. Hackrf Tools
  42. Hacker Tools Online
  43. Hak5 Tools
  44. Hacking Tools Free Download
  45. Hacking Tools Hardware
  46. Hacking Tools Github
  47. Hacker Tools Free Download
  48. Hack Tools Mac
  49. Hack Tools For Windows
  50. Hacker Tools List
  51. Hack Tool Apk No Root
  52. Hacking Tools For Mac
  53. Pentest Tools Bluekeep
  54. Hacking Tools 2019
  55. Hack Tools Download
  56. Pentest Tools Android
  57. Pentest Tools Windows
  58. Pentest Tools Download
  59. Hacker Tools Apk
  60. Hacker
  61. Android Hack Tools Github
  62. Ethical Hacker Tools
  63. Pentest Tools For Android
  64. Termux Hacking Tools 2019
  65. Hacker Tools 2020
  66. Hacking Tools Software
  67. Hack Tools 2019
  68. Pentest Tools Github
  69. Hack Tools Github
  70. Hacker Tool Kit
  71. Hack Tools For Games
  72. Hacking Tools For Mac
  73. Pentest Tools Review
  74. Top Pentest Tools
  75. Bluetooth Hacking Tools Kali
  76. Hacking Tools Mac
  77. Top Pentest Tools
  78. World No 1 Hacker Software
  79. Hacker
  80. Pentest Recon Tools
  81. Hacker Tools Mac
  82. Hak5 Tools
  83. Hacking Tools Usb
  84. Pentest Tools
  85. Pentest Tools Windows
  86. Hacking Tools Mac
  87. Pentest Tools Open Source
  88. Hacker Tools For Pc
  89. Hacks And Tools
  90. Hacker Tools Free Download
  91. Hacker Tools 2019
  92. Hacking Tools Download
  93. Hacker Tools Software
  94. Hacking Apps
  95. Hacking Tools For Pc
  96. Hacker Tools Windows
  97. Pentest Tools
  98. Hack And Tools
  99. Hacking Tools Github
  100. Pentest Tools Online
  101. Best Hacking Tools 2019
  102. Hack Tools
  103. Pentest Tools Website Vulnerability
  104. How To Install Pentest Tools In Ubuntu
  105. Physical Pentest Tools

No comments:

Post a Comment