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

No comments:

Post a Comment