diff options
| author | chenzizhan <[email protected]> | 2023-07-24 15:41:21 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2023-07-24 15:41:21 +0800 |
| commit | 911164f3433279a2d199be2fa2d267368bc55a61 (patch) | |
| tree | d888e69552f1b1e47ebbde91af6a174d11adadd4 /test/test_merge.cpp | |
| parent | 2bf8cbf5ae1773b6d0a517d4488df7f36cad4df2 (diff) | |
id tag map to array
Diffstat (limited to 'test/test_merge.cpp')
| -rw-r--r-- | test/test_merge.cpp | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/test/test_merge.cpp b/test/test_merge.cpp index 4dae338..4b1a5ee 100644 --- a/test/test_merge.cpp +++ b/test/test_merge.cpp @@ -141,7 +141,9 @@ TEST(unit_test_merge, merge_existing_cell_on_existing_cube_and_metric_comprehens fieldstat_counter_incrby(instance, cube_id, metric_id, cell_id, 5); struct fieldstat *instance_dest = fieldstat_new(); + printf("first merge\n"); fieldstat_merge(instance_dest, instance); + printf("2nd merge\n"); fieldstat_merge(instance_dest, instance); int *cube_id_dest; @@ -231,7 +233,7 @@ TEST(unit_test_merge, new_too_many_cells_on_multiple_metric_given_source_cube_re fieldstat_free(instance_dest); } -TEST(unit_test_merge, merge_by_matching_shared_tags_comprehensive) +TEST(unit_test_merge, merge_by_matching_shared_tags) { // todo } @@ -452,11 +454,6 @@ TEST(unit_test_merge, new_too_many_cells_on_multiple_metric_given_source_cube_re fieldstat_free(instance_dest); } -TEST(unit_test_merge, merge_by_matching_shared_tags_topk) -{ - // todo -} - TEST(unit_test_merge, merge_by_matching_metric_names_topk) { // todo @@ -522,7 +519,56 @@ TEST(unit_test_merge, performance_test_when_comprehensive_sampling) } TEST(unit_test_merge, performance_test_when_topk_sampling){ + const int INSTANCE_NUM = 100; + const int MAX_CELL_NUM = 1024; + const int DIMENSION_TOTAL = 100000; + Fieldstat_tag_list_wrapper *tags[DIMENSION_TOTAL]; + for (int i = 0; i < DIMENSION_TOTAL; i++) + { + if (i%2) + tags[i] = new Fieldstat_tag_list_wrapper("my key", i); + else + tags[i] = new Fieldstat_tag_list_wrapper("elephant", i % 1024); + } + + struct fieldstat *instances[INSTANCE_NUM]; + for (int i = 0; i < INSTANCE_NUM; i++) { + struct fieldstat *tmp_i = fieldstat_new(); + int cube_id = fieldstat_register_cube(tmp_i, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOPK, MAX_CELL_NUM); + int metric_id = fieldstat_register_counter(tmp_i, cube_id, "metric name", false); + for (int j = 0; j < MAX_CELL_NUM; j++) { + int cell_id = fieldstat_cube_add(tmp_i, cube_id, tags[rand() % DIMENSION_TOTAL]->get_tag(), 1, 1); + if (cell_id == -1) { + continue; + } + fieldstat_counter_incrby(tmp_i, cube_id, metric_id, cell_id, 1); + } + instances[i] = tmp_i; + } + struct fieldstat *instance_dest = fieldstat_new(); + reset_hash_count(); + clock_t start = clock(); + // getchar(); + for (int i = 0; i < INSTANCE_NUM; i++) { + fieldstat_merge(instance_dest, instances[i]); + } + // exit(0); + clock_t end = clock(); + + double elapsed_secs = double(end - start) / CLOCKS_PER_SEC; + printf("performance_test_when_comprehensive_sampling elapsed_secs: %f\n", elapsed_secs); + printf("get hash count: %d\n", tmp_get_hash_count()); + printf("get simple hash count: %d\n", tmp_get_simple_hash_count()); + EXPECT_TRUE(elapsed_secs < 0.2); // fixme: approximately around 100 cube(templates), 10 metrics. So 0.005s finish it. + + fieldstat_free(instance_dest); + for (int i = 0; i < INSTANCE_NUM; i++) { + fieldstat_free(instances[i]); + } + for (int i = 0; i < DIMENSION_TOTAL; i++) { + delete tags[i]; + } } int main(int argc, char *argv[]) |
