-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbase_allocator.cpp
More file actions
40 lines (34 loc) · 1 KB
/
base_allocator.cpp
File metadata and controls
40 lines (34 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*!
* \brief The basic use of allocator.
*/
#include <iostream>
#include <vector>
#include <tbb/tbb.h>
#include <tbb/scalable_allocator.h>
int main() {
tbb::tick_count start_time, end_time;
const int num = 1000;
const int len = 10000000;
float **mem_container = (float **)malloc(num * sizeof(float *));
// Serial.
start_time = tbb::tick_count::now();
for (int i = 0; i < num; i++) {
mem_container[i] = (float *)malloc(len * sizeof(float));
}
for (int i = 0; i < num; i++) {
free(mem_container[i]);
}
end_time = tbb::tick_count::now();
std::cout << (end_time - start_time).seconds() << std::endl;
// TBB. scalable_calloc, scalable_realloc.
start_time = tbb::tick_count::now();
for (int i = 0; i < num; i++) {
mem_container[i] = (float *)scalable_malloc(len * sizeof(float)); // Faster.
}
for (int i = 0; i < num; i++) {
scalable_free(mem_container[i]);
}
end_time = tbb::tick_count::now();
std::cout << (end_time - start_time).seconds() << std::endl;
return 0;
}