Удаление combite3 функций, изменение названий параметров функицй combine и exclude
This commit is contained in:
parent
54c762da14
commit
5425206401
10 changed files with 277 additions and 220 deletions
218
basic-geometry-dev/turn3_combination.c
Normal file
218
basic-geometry-dev/turn3_combination.c
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif // _WINDOWS_
|
||||
|
||||
#include "printing_utils.h"
|
||||
#include "turn3_combination.h"
|
||||
|
||||
// =================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
BGC_FP32_Turn3 versor1, versor2, result;
|
||||
} Testing_FP32_Turn3Structure;
|
||||
|
||||
typedef struct {
|
||||
BGC_FP64_Turn3 versor1, versor2, result;
|
||||
} Testing_FP64_Turn3Structure;
|
||||
|
||||
// ================= Allocation ================= //
|
||||
|
||||
static Testing_FP32_Turn3Structure* _fp32_allocate_structures(const unsigned int amount)
|
||||
{
|
||||
return malloc((size_t)amount * sizeof(Testing_FP32_Turn3Structure));
|
||||
}
|
||||
|
||||
static Testing_FP64_Turn3Structure* _fp64_allocate_structures(const unsigned int amount)
|
||||
{
|
||||
return malloc((size_t)amount * sizeof(Testing_FP64_Turn3Structure));
|
||||
}
|
||||
|
||||
// =============== Randomization ================ //
|
||||
|
||||
static Testing_FP32_Turn3Structure* _fp32_make_structures(const unsigned int amount)
|
||||
{
|
||||
Testing_FP32_Turn3Structure* list = _fp32_allocate_structures(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplier = 2.0f / RAND_MAX;
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
bgc_fp32_turn3_set_values(
|
||||
&list[i].versor1,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f
|
||||
);
|
||||
|
||||
bgc_fp32_turn3_set_values(
|
||||
&list[i].versor2,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f
|
||||
);
|
||||
|
||||
bgc_fp32_turn3_reset(&list[i].result);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static Testing_FP64_Turn3Structure* _fp64_make_structures(const unsigned int amount)
|
||||
{
|
||||
Testing_FP64_Turn3Structure* list = _fp64_allocate_structures(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const double multiplier = 2.0 / RAND_MAX;
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
bgc_fp64_turn3_set_values(
|
||||
&list[i].versor1,
|
||||
rand() * multiplier - 1.0,
|
||||
rand() * multiplier - 1.0,
|
||||
rand() * multiplier - 1.0,
|
||||
rand() * multiplier - 1.0
|
||||
);
|
||||
|
||||
bgc_fp64_turn3_set_values(
|
||||
&list[i].versor2,
|
||||
rand() * multiplier - 1.0,
|
||||
rand() * multiplier - 1.0,
|
||||
rand() * multiplier - 1.0,
|
||||
rand() * multiplier - 1.0
|
||||
);
|
||||
|
||||
bgc_fp64_turn3_reset(&list[i].result);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// ================ Circle Work ================= //
|
||||
|
||||
static int_fast64_t _fp32_circle_work(const uint_fast32_t amount, Testing_FP32_Turn3Structure* list)
|
||||
{
|
||||
int_fast64_t total = 0;
|
||||
|
||||
for (uint_fast32_t j = 0; j < 1000; j++) {
|
||||
for (uint_fast32_t i = 0; i < amount; i++) {
|
||||
bgc_fp32_turn3_combine(&list[i].result, &list[i].versor1, &list[i].versor2);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
static int_fast64_t _fp64_circle_work(const uint_fast32_t amount, Testing_FP64_Turn3Structure* list)
|
||||
{
|
||||
int_fast64_t total = 0;
|
||||
|
||||
for (uint_fast32_t j = 0; j < 1000; j++) {
|
||||
for (uint_fast32_t i = 0; i < amount; i++) {
|
||||
bgc_fp64_turn3_combine(&list[i].result, &list[i].versor1, &list[i].versor2);
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
// ==================== Test ==================== //
|
||||
|
||||
void test_fp32_turn3_combination()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
int_fast64_t total = 0;
|
||||
Testing_FP32_Turn3Structure* list = _fp32_make_structures(amount);
|
||||
|
||||
#ifdef _WIN64
|
||||
ULONGLONG start, end;
|
||||
|
||||
start = GetTickCount64();
|
||||
|
||||
srand((unsigned int)(start & 0xfffffff));
|
||||
|
||||
start = GetTickCount64();
|
||||
#else
|
||||
struct timespec start, end;
|
||||
clock_gettime(0, &start);
|
||||
srand((unsigned int)(start.tv_nsec & 0xfffffff));
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
#endif // _WIN64
|
||||
|
||||
total = _fp32_circle_work(amount, list);
|
||||
|
||||
#ifdef _WIN64
|
||||
end = GetTickCount64();
|
||||
|
||||
printf("Time: %lld, Total iterations: %ld\n", end - start, total);
|
||||
#else
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
|
||||
printf("Time: %lf, Total iterations: %ld\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001, total);
|
||||
#endif // _WIN64
|
||||
|
||||
print_fp32_quaternion(&list[10].versor1._versor);
|
||||
print_fp32_quaternion(&list[10].versor2._versor);
|
||||
print_fp32_quaternion(&list[10].result._versor);
|
||||
|
||||
free(list);
|
||||
}
|
||||
|
||||
|
||||
void test_fp64_turn3_combination()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
int_fast64_t total = 0;
|
||||
Testing_FP64_Turn3Structure* list = _fp64_make_structures(amount);
|
||||
|
||||
#ifdef _WIN64
|
||||
ULONGLONG start, end;
|
||||
|
||||
start = GetTickCount64();
|
||||
|
||||
srand((unsigned int)(start & 0xfffffff));
|
||||
|
||||
start = GetTickCount64();
|
||||
#else
|
||||
struct timespec start, end;
|
||||
clock_gettime(0, &start);
|
||||
srand((unsigned int)(start.tv_nsec & 0xfffffff));
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
#endif // _WIN64
|
||||
|
||||
total = _fp64_circle_work(amount, list);
|
||||
|
||||
#ifdef _WIN64
|
||||
end = GetTickCount64();
|
||||
|
||||
printf("Time: %lld, Total iterations: %ld\n", end - start, total);
|
||||
#else
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
|
||||
printf("Time: %lf, Total iterations: %ld\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001, total);
|
||||
#endif // _WIN64
|
||||
|
||||
print_fp64_quaternion(&list[10].versor1._versor);
|
||||
print_fp64_quaternion(&list[10].versor2._versor);
|
||||
print_fp64_quaternion(&list[10].result._versor);
|
||||
|
||||
free(list);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue