Skip to content

Commit 426caca

Browse files
authored
Rust vs C++ Performance: Can Rust Actually Be Faster? (Pt. 2) (#477)
1 parent 6f2ed8e commit 426caca

30 files changed

+2149
-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/wP1wz6MhxcI
1+
# New Video - https://youtu.be/5-sDEDBJPlY
22

3-
[<img src="assets/264.png?raw=true">](https://youtu.be/wP1wz6MhxcI)
3+
[<img src="assets/265.png?raw=true">](https://youtu.be/5-sDEDBJPlY)
44

55
# Consulting
66

assets/264.png

-571 KB
Binary file not shown.

assets/265.png

516 KB
Loading

docs/contents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,4 @@
186186
- [258 - Redis vs Valkey performance](../lessons/258)
187187
- [259 - Rust vs C++ Performance: Can Rust Actually Be Faster?](../lessons/259)
188188
- [260 - ZeroMQ vs Aeron: Best for Market Data? Performance (Latency & Throughput)](../lessons/260)
189+
- [265 - Rust vs C++ Performance: Can Rust Actually Be Faster? (Pt. 2)](../lessons/265)

lessons/265/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? (Pt. 2)
2+
3+
You can find tutorial [here](https://youtu.be/5-sDEDBJPlY).
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/265/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/265/app-cpp/CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
src/utils.cpp
23+
)
24+
25+
find_package(boost_beast CONFIG REQUIRED)
26+
find_package(boost_json CONFIG REQUIRED)
27+
find_package(spdlog CONFIG REQUIRED)
28+
29+
include_directories(include)
30+
31+
# Set VCPKG triplet based on platform
32+
if(APPLE)
33+
set(VCPKG_TARGET_TRIPLET "arm64-osx")
34+
elseif(UNIX AND NOT APPLE)
35+
set(VCPKG_TARGET_TRIPLET "x64-linux")
36+
endif()
37+
38+
# Link libraries
39+
target_link_libraries(app
40+
PRIVATE
41+
Boost::beast
42+
Boost::json
43+
spdlog::spdlog
44+
)
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef BOOK_TICKER_HPP
2+
#define BOOK_TICKER_HPP
3+
4+
#include <string>
5+
#include <vector>
6+
7+
struct BookTicker {
8+
std::string symbol;
9+
std::string bidPrice;
10+
std::string bidQty;
11+
std::string askPrice;
12+
std::string askQty;
13+
};
14+
15+
std::string serialize_book_tickers(const std::vector<BookTicker>& tickers);
16+
17+
#endif // BOOK_TICKER_HPP

0 commit comments

Comments
 (0)