From 7aa6f65fd4de03f3006ca119fab36441d7e5c4dc Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 14 Jan 2023 19:56:36 +0800 Subject: [PATCH] update: perf benchmark for basic ranges demo --- src/all_cases/basic_ranges.cc | 28 +------ src/basic_ranges_demo.cc | 153 +++++++++++++++++----------------- src/main.cc | 4 +- 3 files changed, 81 insertions(+), 104 deletions(-) diff --git a/src/all_cases/basic_ranges.cc b/src/all_cases/basic_ranges.cc index ef437eb..e999b18 100644 --- a/src/all_cases/basic_ranges.cc +++ b/src/all_cases/basic_ranges.cc @@ -45,8 +45,6 @@ void BasicRanges::build() { // ensure that basic ranges available } } -#include - void BasicRanges::build_data() { // build basic ranges BasicRanges::data.reserve(BASIC_RANGES_SIZE); // memory pre-allocated for (int n = 0; n <= 7; ++n) { // number of 1x2 and 2x1 block -> 0 ~ 7 @@ -54,33 +52,15 @@ void BasicRanges::build_data() { // build basic ranges for (int n_1x1 = 0; n_1x1 <= (14 - n * 2); ++n_1x1) { // number of 1x1 block -> 0 ~ (14 - 2n) int n_1x2 = n - n_2x1; int n_space = 16 - n * 2 - n_1x1; - -// if (n_space == 7 && n_1x2 == 2 && n_2x1 == 1 && n_1x1 == 3) { -// std::cout << "Start: " << data.size() << std::endl; -// } - if (n_space == 6 && n_1x2 == 2 && n_2x1 == 1 && n_1x1 == 4) { - std::cout << "Start: " << data.size() << std::endl; - } - /// (7, 2, 1, 3) -> 102960 - /// (6, 2, 1, 4) -> 180180 - generate(n_space, n_1x2, n_2x1, n_1x1); // generate target ranges /// 0x0 -> 00 | 1x2 -> 01 | 2x1 -> 10 | 1x1 -> 11 - -// if (n_space == 7 && n_1x2 == 2 && n_2x1 == 1 && n_1x1 == 3) { -// std::cout << "End: " << data.size() << std::endl; -// } - if (n_space == 6 && n_1x2 == 2 && n_2x1 == 1 && n_1x1 == 4) { - std::cout << "End: " << data.size() << std::endl; - } - } } } - std::sort(BasicRanges::data.begin(), BasicRanges::data.end()); // sort basic ranges - for (auto &range : BasicRanges::data) { - range = Common::range_reverse(range); // basic ranges reverse - } +// std::sort(BasicRanges::data.begin(), BasicRanges::data.end()); // sort basic ranges +// for (auto &range : BasicRanges::data) { +// range = Common::range_reverse(range); // basic ranges reverse +// } } void BasicRanges::generate(int n1, int n2, int n3, int n4) { // generate specific basic ranges diff --git a/src/basic_ranges_demo.cc b/src/basic_ranges_demo.cc index 29b2870..75aae0b 100644 --- a/src/basic_ranges_demo.cc +++ b/src/basic_ranges_demo.cc @@ -1,6 +1,7 @@ #include "basic_ranges_demo.h" #include +#include struct br_t { int n1; @@ -9,18 +10,11 @@ struct br_t { int n4; }; -void show_br_t(br_t &dat) { - printf("(%d, %d, %d, %d)", dat.n1, dat.n2, dat.n3, dat.n4); -} +//std::vector release_data; -br_t dat[] = { -// {2, 0, 0, 1}, -// {1, 0, 2, 0}, -// {7, 2, 1, 3}, -// {6, 2, 1, 4}, -// {5, 2, 1, 5}, -// {4, 2, 1, 6}, +br_t dat_s; +br_t dat[] = { {16, 0, 0, 0}, {15, 0, 0, 1}, {14, 0, 0, 2}, @@ -241,88 +235,80 @@ void func(uint32_t prefix, int offset) { // printf(" | prefix = %08X | offset = %d\n", prefix, offset); -// if (dat[0].n1 == 0 && dat[0].n2 == 0 && dat[0].n3 == 0 && dat[0].n4 == 0) { + if (dat_s.n1 == 0 && dat_s.n2 == 0 && dat_s.n3 == 0 && dat_s.n4 == 0) { // printf("release -> %08X\n", prefix); -// return; -// } -// if (dat[1].n1 == 0 && dat[1].n2 == 0 && dat[1].n3 == 0 && dat[1].n4 == 0) { -// printf("release -> %08X\n", prefix); -// return; -// } - - for (int i = 0; i < dat_size; ++i) { - if (dat[i].n1 == 0 && dat[i].n2 == 0 && dat[i].n3 == 0 && dat[i].n4 == 0) { - printf("release -> %08X\n", prefix); - return; - } + return; } -// if ((dat[0].n1 < 0 || dat[0].n2 < 0 || dat[0].n3 < 0 || dat[0].n4 < 0) && (dat[1].n1 < 0 || dat[1].n2 < 0 || dat[1].n3 < 0 || dat[1].n4 < 0)) { -// std::cout << "break" << std::endl; -// return; +// for (int i = 0; i < dat_size; ++i) { +// if (dat[i].n1 == 0 && dat[i].n2 == 0 && dat[i].n3 == 0 && dat[i].n4 == 0) { +//// printf("release -> %08X\n", prefix); +// return; +// } // } - bool flag = false; - for (int i = 0; i < dat_size; ++i) { - if (!(dat[i].n1 < 0 || dat[i].n2 < 0 || dat[i].n3 < 0 || dat[i].n4 < 0)) { - flag = true; - } - } - if (!flag) { + if (dat_s.n1 < 0 || dat_s.n2 < 0 || dat_s.n3 < 0 || dat_s.n4 < 0) { +// std::cout << "break" << std::endl; return; } - // generate start with 00 -// --dat[0].n1; -// --dat[1].n1; - for (int i = 0; i < dat_size; ++i) { - --dat[i].n1; - } +// bool flag = false; +// for (int i = 0; i < dat_size; ++i) { +// if (!(dat[i].n1 < 0 || dat[i].n2 < 0 || dat[i].n3 < 0 || dat[i].n4 < 0)) { +// flag = true; +// } +// } +// if (!flag) { +// return; +// } + + /// generate start with 00 + --dat_s.n1; func(prefix | ((uint32_t)0b00 << 30) >> offset, offset + 2); -// ++dat[0].n1; -// ++dat[1].n1; - for (int i = 0; i < dat_size; ++i) { - ++dat[i].n1; - } + ++dat_s.n1; +// for (int i = 0; i < dat_size; ++i) { +// --dat[i].n1; +// } +// func(prefix | ((uint32_t)0b00 << 30) >> offset, offset + 2); +// for (int i = 0; i < dat_size; ++i) { +// ++dat[i].n1; +// } - // generate start with 01 -// --dat[0].n2; -// --dat[1].n2; - for (int i = 0; i < dat_size; ++i) { - --dat[i].n2; - } + /// generate start with 01 + --dat_s.n2; func(prefix | ((uint32_t)0b01 << 30) >> offset, offset + 2); -// ++dat[0].n2; -// ++dat[1].n2; - for (int i = 0; i < dat_size; ++i) { - ++dat[i].n2; - } + ++dat_s.n2; +// for (int i = 0; i < dat_size; ++i) { +// --dat[i].n2; +// } +// func(prefix | ((uint32_t)0b01 << 30) >> offset, offset + 2); +// for (int i = 0; i < dat_size; ++i) { +// ++dat[i].n2; +// } - // generate start with 10 -// --dat[0].n3; -// --dat[1].n3; - for (int i = 0; i < dat_size; ++i) { - --dat[i].n3; - } + /// generate start with 10 + --dat_s.n3; func(prefix | ((uint32_t)0b10 << 30) >> offset, offset + 2); -// ++dat[0].n3; -// ++dat[1].n3; - for (int i = 0; i < dat_size; ++i) { - ++dat[i].n3; - } + ++dat_s.n3; +// for (int i = 0; i < dat_size; ++i) { +// --dat[i].n3; +// } +// func(prefix | ((uint32_t)0b10 << 30) >> offset, offset + 2); +// for (int i = 0; i < dat_size; ++i) { +// ++dat[i].n3; +// } - // generate start with 11 -// --dat[0].n4; -// --dat[1].n4; - for (int i = 0; i < dat_size; ++i) { - --dat[i].n4; - } + /// generate start with 11 + --dat_s.n4; func(prefix | ((uint32_t)0b11 << 30) >> offset, offset + 2); -// ++dat[0].n4; -// ++dat[1].n4; - for (int i = 0; i < dat_size; ++i) { - ++dat[i].n4; - } + ++dat_s.n4; +// for (int i = 0; i < dat_size; ++i) { +// --dat[i].n4; +// } +// func(prefix | ((uint32_t)0b11 << 30) >> offset, offset + 2); +// for (int i = 0; i < dat_size; ++i) { +// ++dat[i].n4; +// } } @@ -344,7 +330,18 @@ void load_ranges() { // } // } - func(0, 0); + +// release_data.reserve(8000000); + + for (int i = 0; i < dat_size; ++i) { + dat_s = dat[i]; + func(0, 0); + } + + +// dat_s = {3, 1, 3, 5}; +// +// func(0, 0); // br_t demo = {2, 0, 0, 1}; diff --git a/src/main.cc b/src/main.cc index c5b8afb..2abbe27 100644 --- a/src/main.cc +++ b/src/main.cc @@ -246,8 +246,8 @@ int main() { // BasicRanges::build(); -// std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; - std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; + std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; +// std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; // std::cout << "complete benchmark" << std::endl; // pause();