Skip to content

Instantly share code, notes, and snippets.

@bakercp
Created April 30, 2017 02:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakercp/157573d1e27eec5f6fe4467c98477aa7 to your computer and use it in GitHub Desktop.
Save bakercp/157573d1e27eec5f6fe4467c98477aa7 to your computer and use it in GitHub Desktop.
dlib SIMD tests
#include <dlib/image_io.h>
#include <dlib/image_transforms.h>
using namespace std;
using namespace dlib;
int main(int argc, char** argv)
{
try
{
int numRuns = 100;
double sum = 0.0;
for (int i = 0; i < numRuns; ++i)
{
matrix<unsigned char, 1536, 2048> img;
dlib::array<array2d<double>> hog;
chrono::system_clock::time_point start = chrono::system_clock::now();
impl_fhog::impl_extract_fhog_features(img, hog, 8, 1, 1);
chrono::system_clock::time_point end = chrono::system_clock::now();
double msec = std::chrono::duration_cast<chrono::milliseconds>(end - start).count();
sum += msec;
}
cout << "~" << (sum / numRuns) << " ms" << endl;
}
catch (exception& e)
{
cout << "exception thrown: " << e.what() << endl;
}
}
@bakercp
Copy link
Author

bakercp commented Apr 30, 2017

Place this in your your dlib/examples folder and compile and run with something like ...

cd dlib/examples
// copy the file in to this directory

Note that this will run 100 times and output the average time in milliseconds, so on a really slow processor it could take a while.

macOS

with default

g++ -DDLIB_NO_GUI_SUPPORT -DNO_MAKEFILE -std=c++11 -O3 -I.. -lpthread fhog_simd_ex.cpp && ./a.out 

with avx

g++ -DDLIB_NO_GUI_SUPPORT -DNO_MAKEFILE -std=c++11 -O3 -mavx -I.. -lpthread fhog_simd_ex.cpp && ./a.out

Ubuntu

with default

g++ -DDLIB_NO_GUI_SUPPORT -DNO_MAKEFILE -std=c++11 -O3 -I.. -pthread fhog_simd_ex.cpp && ./a.out 

with avx

g++ -DDLIB_NO_GUI_SUPPORT -DNO_MAKEFILE -std=c++11 -O3 -mavx -I.. -pthread fhog_simd_ex.cpp && ./a.out

Raspberry Pi 3

with default

g++ -DDLIB_NO_GUI_SUPPORT -DNO_MAKEFILE -std=c++11 -O3 -I.. -lpthread fhog_simd_ex.cpp && ./a.out 

with neon

g++ -DDLIB_NO_GUI_SUPPORT -DNO_MAKEFILE -std=c++11 -O3 -mfpu=neon -I.. -lpthread fhog_simd_ex.cpp && ./a.out

@MiXaiLL76
Copy link

Orange Pi Zero plus 2 (armbian)

neon not worked on aarch64

g++ -DDLIB_NO_GUI_SUPPORT -DNO_MAKEFILE -std=c++11 -O3 -I.. -lpthread fhog_simd_ex.cpp && ./a.out 

result single core

~450.77 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment