Skip to content

Commit

Permalink
Benchmarks progress
Browse files Browse the repository at this point in the history
  • Loading branch information
desatur committed Aug 29, 2024
1 parent a4a4690 commit e7de112
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/benchmark"]
path = lib/benchmark
url = https://github.com/google/benchmark.git
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ cmake_minimum_required(VERSION 3.29)
project(Future)

set(CMAKE_CXX_STANDARD 20)
set(BENCHMARK_ENABLE_TESTING OFF)

add_library(Future STATIC FutureEngine.cpp
Structs/Vector2.cpp
Structs/Vector3.cpp
# Add the source files for your library
add_library(Future STATIC
src/FutureEngine.cpp
src/Structs/Vector2.cpp
src/Structs/Vector3.cpp
src/Structs/Vector2.h
src/Structs/Vector3.h
)

# Benchmarks
add_subdirectory(lib/benchmark)
target_link_libraries(Future PUBLIC benchmark::benchmark benchmark::benchmark_main)
add_executable(vector_benchmark benchmarks/vector_benchmark.cpp)
target_link_libraries(vector_benchmark Future benchmark::benchmark benchmark::benchmark_main)
Empty file added benchmarks/benchmark_main.cpp
Empty file.
26 changes: 26 additions & 0 deletions benchmarks/vector_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <benchmark/benchmark.h>
#include "../src/Structs/Vector2.h"
#include "../src/Structs/Vector3.h"

// Example benchmark for Vector2
static void BM_Vector2_Addition(benchmark::State& state) {
Vector2 a(1.0f, 2.0f);
Vector2 b(3.0f, 4.0f);
for (auto _ : state) {
benchmark::DoNotOptimize(a + b);
}
}
BENCHMARK(BM_Vector2_Addition);

// Example benchmark for Vector3
static void BM_Vector3_Addition(benchmark::State& state) {
Vector3 a(1.0f, 2.0f, 3.0f);
Vector3 b(4.0f, 5.0f, 6.0f);
for (auto _ : state) {
benchmark::DoNotOptimize(a + b);
}
}
BENCHMARK(BM_Vector3_Addition);

// Main function to run benchmarks
BENCHMARK_MAIN();
1 change: 1 addition & 0 deletions lib/benchmark
Submodule benchmark added at c19cfe
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions src/Structs/Vector2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef VECTOR2_H
#define VECTOR2_H

#include <cmath>

struct Vector2 {
float x, y;

Vector2(float x = 0, float y = 0); // Constructor

// Magnitude of the vector
float magnitude() const;

// Normalized vector
Vector2 normalized() const;

// Dot product
float dot(const Vector2& other) const;

// Addition
Vector2 operator+(const Vector2& other) const;

// Subtraction
Vector2 operator-(const Vector2& other) const;

// Multiplication by scalar
Vector2 operator*(float scalar) const;

// Division by scalar
Vector2 operator/(float scalar) const;

// Equality check
bool operator==(const Vector2& other) const;
};

#endif // VECTOR2_H
File renamed without changes.
42 changes: 42 additions & 0 deletions src/Structs/Vector3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef VECTOR3_H
#define VECTOR3_H

#include <cmath>

struct Vector3 {
float x, y, z;

Vector3(float x = 0, float y = 0, float z = 0); // Constructor

// Magnitude of the vector
float magnitude() const;

// Normalized vector
Vector3 normalized() const;

// Dot product
float dot(const Vector3& other) const;

// Cross product
Vector3 cross(const Vector3& other) const;

// Addition
Vector3 operator+(const Vector3& other) const;

// Subtraction
Vector3 operator-(const Vector3& other) const;

// Multiplication by scalar
Vector3 operator*(float scalar) const;

// Division by scalar
Vector3 operator/(float scalar) const;

// Equality check
bool operator==(const Vector3& other) const;

// Inequality check
bool operator!=(const Vector3& other) const;
};

#endif // VECTOR3_H

0 comments on commit e7de112

Please sign in to comment.