forked from Itsposs/cppstl
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_array.cc
More file actions
40 lines (33 loc) · 1.12 KB
/
Copy pathtest_array.cc
File metadata and controls
40 lines (33 loc) · 1.12 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
#include "util.h"
#include <ctime>
#include <cstdlib> // qsort,bsearch,NULL
#include <array>
#include <iostream>
namespace jj01
{
void test_array()
{
std::cout << "\ntest_array()...........\n";
std::array<long, ASIZE> c;
clock_t timeStart = clock();
for(long i = 0; i < ASIZE; ++i)
{
c[i] = rand();
}
std::cout << "milli-seconds: " << (clock() - timeStart) << std::endl;
std::cout << "array.size()= " << c.size() << std::endl;
std::cout << "array.max_size()= " << c.max_size() << std::endl;
std::cout << "array.front()= " << c.front() << std::endl;
std::cout << "array.back()= " << c.back() << std::endl;
std::cout << "array.data()= " << c.data() << std::endl;
long target = util::get_a_target_long();
timeStart = clock();
qsort(c.data(), ASIZE, sizeof(long), util::compareLongs);
long* pItem = (long*)bsearch(&target, (c.data()), ASIZE, sizeof(long), util::compareLongs);
std::cout << "qsort() + bsearch(),milli-seconds : " << (clock() - timeStart)<< std::endl;
if(pItem != NULL)
std::cout << "found, " << *pItem << std::endl;
else
std::cout << "not found! " << std::endl;
}
}