Skip to content

Commit 63db0ef

Browse files
authored
Rust vs C++ Performance: Can Rust Actually Be Faster? (#473)
1 parent e00fd92 commit 63db0ef

28 files changed

+2200
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# New Video - https://youtu.be/TQ_V9TYoRvw
1+
# New Video - https://youtu.be/J6YVX7E5QPE
22

3-
[<img src="assets/256.png?raw=true">](https://youtu.be/TQ_V9TYoRvw)
3+
[<img src="assets/263.png?raw=true">](https://youtu.be/J6YVX7E5QPE)
44

55
# Consulting
66

assets/256.png

-226 KB
Binary file not shown.

assets/263.png

570 KB
Loading

docs/contents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,4 @@
184184
- [255 - Terraform Tutorial on AWS](../lessons/255)
185185
- [256 - Terraform AWS VPC Tutorial - Public, Private, and Isolated Subnets](../lessons/256)
186186
- [258 - Redis vs Valkey performance](../lessons/258)
187+
- [259 - Rust vs C++ Performance: Can Rust Actually Be Faster?](../lessons/259)

lessons/263/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Rust vs C++ Performance: Can Rust Actually Be Faster?
2+
3+
You can find tutorial [here](https://youtu.be/J6YVX7E5QPE).
4+
5+
## Commands
6+
7+
```bash
8+
## C++
9+
cmake --preset default -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="-O3 -ffast-math"
10+
cmake --build build && ./build/app
11+
12+
## Rust
13+
cargo build --release
14+
```

lessons/263/app-cpp/.clang-format

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
AccessModifierOffset: -4
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignOperands: true
8+
AlignTrailingComments: false
9+
AlwaysBreakTemplateDeclarations: Yes
10+
BraceWrapping:
11+
AfterCaseLabel: false
12+
AfterClass: false
13+
AfterControlStatement: false
14+
AfterEnum: false
15+
AfterFunction: false
16+
AfterNamespace: false
17+
AfterStruct: false
18+
AfterUnion: false
19+
AfterExternBlock: false
20+
BeforeCatch: false
21+
BeforeElse: false
22+
BeforeLambdaBody: false
23+
BeforeWhile: false
24+
SplitEmptyFunction: true
25+
SplitEmptyRecord: true
26+
SplitEmptyNamespace: true
27+
BreakBeforeBraces: Custom
28+
BreakConstructorInitializers: AfterColon
29+
BreakConstructorInitializersBeforeComma: false
30+
ColumnLimit: 0
31+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
32+
ContinuationIndentWidth: 8
33+
IncludeCategories:
34+
- Regex: '^<.*'
35+
Priority: 1
36+
- Regex: '^".*'
37+
Priority: 2
38+
- Regex: '.*'
39+
Priority: 3
40+
IncludeIsMainRegex: '([-_](test|unittest))?$'
41+
IndentCaseLabels: true
42+
IndentWidth: 4
43+
InsertNewlineAtEOF: true
44+
MacroBlockBegin: ''
45+
MacroBlockEnd: ''
46+
MaxEmptyLinesToKeep: 2
47+
NamespaceIndentation: All
48+
SpaceAfterCStyleCast: true
49+
SpaceAfterTemplateKeyword: false
50+
SpaceBeforeRangeBasedForLoopColon: false
51+
SpaceInEmptyParentheses: false
52+
SpacesInAngles: false
53+
SpacesInConditionalStatement: false
54+
SpacesInCStyleCastParentheses: false
55+
SpacesInParentheses: false
56+
TabWidth: 4

lessons/263/app-cpp/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Specify the minimum required CMake version
2+
cmake_minimum_required(VERSION 3.28)
3+
4+
# Define the project
5+
project(app-cpp
6+
VERSION 0.1.0
7+
DESCRIPTION "Simple HTTP server."
8+
LANGUAGES CXX
9+
)
10+
11+
# Set C++ standard to C++20 for all targets
12+
set(CMAKE_CXX_STANDARD 20)
13+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
14+
set(CMAKE_CXX_EXTENSIONS OFF)
15+
16+
# Add executable
17+
add_executable(app
18+
src/main.cpp
19+
src/http_session.cpp
20+
src/listener.cpp
21+
src/book_ticker.cpp
22+
)
23+
24+
find_package(boost_beast CONFIG REQUIRED)
25+
find_package(boost_json CONFIG REQUIRED)
26+
find_package(spdlog CONFIG REQUIRED)
27+
28+
include_directories(include)
29+
30+
# Set VCPKG triplet based on platform
31+
if (APPLE)
32+
set(VCPKG_TARGET_TRIPLET "arm64-osx")
33+
elseif (UNIX AND NOT APPLE)
34+
set(VCPKG_TARGET_TRIPLET "x64-linux")
35+
endif ()
36+
37+
# Link libraries
38+
target_link_libraries(app
39+
PRIVATE
40+
Boost::beast
41+
Boost::json
42+
spdlog::spdlog
43+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 2,
3+
"configurePresets": [
4+
{
5+
"name": "vcpkg",
6+
"generator": "Ninja",
7+
"binaryDir": "${sourceDir}/build",
8+
"cacheVariables": {
9+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
10+
}
11+
}
12+
]
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 2,
3+
"configurePresets": [
4+
{
5+
"name": "default",
6+
"inherits": "vcpkg",
7+
"environment": {
8+
"VCPKG_ROOT": "$env{HOME}/devel/vcpkg"
9+
}
10+
}
11+
]
12+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef BOOK_TICKER_HPP
2+
#define BOOK_TICKER_HPP
3+
4+
#include <boost/beast.hpp>
5+
#include <boost/json.hpp>
6+
#include <string>
7+
#include <vector>
8+
9+
namespace beast = boost::beast;
10+
namespace json = boost::json;
11+
12+
struct BookTicker {
13+
std::string symbol;
14+
std::string bidPrice;
15+
std::string bidQty;
16+
std::string askPrice;
17+
std::string askQty;
18+
};
19+
20+
std::string serialize_book_tickers(const std::vector<BookTicker>& tickers);
21+
22+
void fail(const beast::error_code& ec, char const* what);
23+
24+
#endif // BOOK_TICKER_HPP

0 commit comments

Comments
 (0)