...
 
Commits (4)
source blaar.sh
echo "f_grad.sh"
echo "========="
blaar_init_options "Apply a gradient on input grey image"
blaar_add_option direction d "" "x|y" "direction of the gradient"
blaar_add_option gain g "" "real" "gain" "1"
blaar_add_option output o "" "blc_channel-out" "convolution output" ":grad<pid>"
blaar_add_option output o "" "blc_channel-out" "convolution output" ":grad$$"
blaar_add_option size s "" "(integer)x(interger)" "size of the filter" "3x3"
blaar_add_option sigma S "" "real" "sigma of the filter" -1
blaar_add_option profile p "" "filename" "profile the script" ""
......@@ -12,14 +15,16 @@ blaar_parse_args "$@"
[ "$direction" = "x" ] && option="-x1" || { [ "$direction" = "y" ] && option="-y1"; } || { echo "Wrong direction option '$direction'"; exit 1; }
echo "size:$size" >&2
echo "Profile:$profile" >&2
[ "$profile" != "" ] && profile_option="-~$profile" || profile_option=""
kernel=$(i_gaussian $option -g$gain -s$size -S$sigma -o/d${direction}gaussian$$ -p0 2>$TMP_DIR/log ) || { cat $TMP_DIR/log; echo "Error creating the kernel"; exit 2; }
# -p0 is because we do not want block
#./run.sh ipp/
f_ipp_convolute $profile_option -o$output $image $kernel
f_ipp_convolute $profile_option -o$output $image $kernel
#./run.sh armadillo/f_arma_convolute -o$output -~grad.tsv $image $kernel
#./run.sh bapps/f_conv -o$output -~grad.tsv $image $kernel
......
......@@ -22,6 +22,7 @@ blaar_add_option size s "" "integer" "number of items per buffer" "4096"
blaar_add_option samplerate S "" "integer" "Samplerate of the sound acquisition" "44100"
blaar_parse_args "$@"
[ $filename ] && file_option="--file=$filename" || file_option=""
[ $output ] && output_option="--output=$output"|| output_option=""
if [ $filename ]; then
......
......@@ -32,12 +32,12 @@ if [ $filename ]; then
echo "to '$filename'" >&2
[ $device ] && { echo "You cannot have file (-f $filename) and speaker (-D $device) at the same time"; exit 1; }
o_sndfile --file=$filename --size=$size --samplerate=$samplerate $sound
elif [ $(uname) = "Darwin" ]; then #microphone
elif [ $(uname) = "Darwin" ]; then
echo "to coreaudio speaker" >&2
o_coreaudio $sound
o_coreaudio --samplerate=$samplerate $sound
elif [ $(uname) = "Linux" ]; then
echo "to ALSA speaker" >&2
o_asound $sound
o_asound --samplerate=$samplerate $sound
else
echo "$blaar_program_name does not work on '$(uname)' platform"
exit 1
......
cmake_minimum_required(VERSION 2.6)
project(test_optim)
subdirs(test_c)
subdirs(test_cpp)
Operation `x=x/3+3` on array of 1 000 000 in
With `C -O3 -march=native`
```
Finish '<' 282ms '!=' 254ms '--' 288ms total:825ms
Finish '<' 268ms '!=' 253ms '--' 298ms total:820ms
Finish '<' 272ms '!=' 256ms '--' 298ms total:826ms
Finish '<' 286ms '!=' 264ms '--' 303ms total:854ms
Finish '<' 279ms '!=' 264ms '--' 296ms total:841ms
Finish '<' 276ms '!=' 254ms '--' 305ms total:836ms
Finish '<' 275ms '!=' 262ms '--' 302ms total:840ms
Finish '<' 280ms '!=' 263ms '--' 309ms total:853ms
Finish '<' 269ms '!=' 254ms '--' 297ms total:821ms
Finish '<' 269ms '!=' 254ms '--' 289ms total:813ms
```
With `C++ -O3`
```
Finish c-style: 422ms 361ms 409ms valarray: 362ms vector: 354ms 348ms 353ms total:2613ms
Finish c-style: 367ms 368ms 403ms valarray: 378ms vector: 361ms 358ms 360ms total:2597ms
Finish c-style: 371ms 364ms 412ms valarray: 356ms vector: 359ms 370ms 373ms total:2608ms
Finish c-style: 391ms 362ms 409ms valarray: 356ms vector: 349ms 350ms 364ms total:2585ms
Finish c-style: 369ms 372ms 404ms valarray: 364ms vector: 352ms 352ms 354ms total:2570ms
Finish c-style: 362ms 354ms 432ms valarray: 354ms vector: 360ms 362ms 348ms total:2575ms
Finish c-style: 361ms 355ms 397ms valarray: 355ms vector: 350ms 351ms 351ms total:2523ms
Finish c-style: 377ms 360ms 431ms valarray: 358ms vector: 350ms 351ms 348ms total:2578ms
Finish c-style: 375ms 362ms 413ms valarray: 366ms vector: 352ms 350ms 350ms total:2572ms
Finish c-style: 372ms 364ms 414ms valarray: 350ms vector: 359ms 359ms 360ms total:2580ms
```
With `CPP -O3 -march=native`
```
Finish c-style: 279ms 306ms 307ms valarray: 283ms vector: 285ms 289ms 279ms total:2031ms
Finish c-style: 295ms 335ms 314ms valarray: 295ms vector: 290ms 303ms 288ms total:2124ms
Finish c-style: 285ms 306ms 307ms valarray: 276ms vector: 285ms 286ms 284ms total:2032ms
Finish c-style: 311ms 352ms 332ms valarray: 276ms vector: 293ms 293ms 294ms total:2154ms
Finish c-style: 289ms 310ms 309ms valarray: 272ms vector: 279ms 285ms 283ms total:2031ms
Finish c-style: 294ms 320ms 319ms valarray: 276ms vector: 278ms 275ms 272ms total:2039ms
Finish c-style: 283ms 310ms 307ms valarray: 276ms vector: 295ms 292ms 294ms total:2060ms
Finish c-style: 317ms 315ms 317ms valarray: 277ms vector: 278ms 298ms 281ms total:2088ms
Finish c-style: 285ms 315ms 313ms valarray: 274ms vector: 281ms 277ms 277ms total:2025ms
Finish c-style: 285ms 308ms 305ms valarray: 287ms vector: 279ms 277ms 279ms total:2023ms
```
\ No newline at end of file
#ifndef COMMON_H
#define COMMON_H
#define SIZE 1000000
#define TRIALS_NB 1000
#define OPERATION(x) x=x/3+3
int sum;
#endif
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.cloop</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
#include <stdio.h>
#include <sys/time.h>
#define SIZE 1000000 //1M
#define TRIALS_NB 10000
#define OPERATION tab[i]=k+i/3
int main(){
int i, k;
int tab[SIZE]={0};
int total1=0, total2=0, total3=0, delta;
struct timeval time;
int us_time, us_previous_time;
gettimeofday(&time, NULL);
us_previous_time=time.tv_sec*1000000+time.tv_usec;
for (k=0; k<TRIALS_NB; k++ ){
for (i=0; i<SIZE; i++){
OPERATION;
}
gettimeofday(&time, NULL);
us_time=time.tv_sec*1000000+time.tv_usec;
delta=us_time-us_previous_time;
// fprintf(stderr, "%d loop '<' time: %d \n",tab[0], delta);
total1+=delta;
us_previous_time=us_time;
for (i=0; i!=SIZE; i++){
OPERATION;
}
gettimeofday(&time, NULL);
us_time=time.tv_sec*1000000+time.tv_usec;
delta=us_time-us_previous_time;
// fprintf(stderr, "%d loop '!=' time: %d \n",tab[0], delta);
total2+=delta;
us_previous_time=us_time;
for (i=SIZE-1; i--;){
OPERATION;
}
gettimeofday(&time, NULL);
us_time=time.tv_sec*1000000+time.tv_usec;
delta=us_time-us_previous_time;
// fprintf(stderr, "%d loop '--' time: %d \n", tab[0], delta);
total3+=delta;
us_previous_time=us_time;
}
fprintf(stderr, "Finish %d %d %d\n", total1, total2, total3);
return 0;
}
cmake_minimum_required(VERSION 2.6)
project(test_c)
#SET( CMAKE_C_COMPILER "/usr/local/bin/gcc-9" )
add_definitions(-Wall -W -Wextra ) #-march=native
add_executable(test_c test.c)
#include <stdio.h>
#include <sys/time.h>
#include "../common.h"
//OPERATION(x) is defined in ../common.h like that it is the same for C and C++
#define UPDATE_TIME(total) do{ end_t=clock(); total = (end_t - start_t)*1000 / CLOCKS_PER_SEC; start_t=end_t;}while(0)
int main(){
int i, k;
volatile int result[SIZE]; //volatile is used to be sure that the compiler execute the calcul.
int tab[SIZE]={0};
int total1=0, total2=0, total3=0, total;
clock_t init_t, start_t, end_t;
init_t=start_t = clock();
for (k=0; k<TRIALS_NB; k++ ){
for (i=0; i<SIZE; i++){
OPERATION(tab[i]);
}
}
for (int i=0; i<SIZE; i++) result[i]=tab[i];
UPDATE_TIME(total1);
for (k=0; k<TRIALS_NB; k++ ){
for (i=0; i!=SIZE; i++){
OPERATION(tab[i]);
}
}
for (int i=0; i<SIZE; i++) result[i]=tab[i];
UPDATE_TIME(total2);
for (k=0; k<TRIALS_NB; k++ ){
for (i=SIZE-1; i--;){
OPERATION(tab[i]);
}
}
for (int i=0; i<SIZE; i++) result[i]=tab[i];
UPDATE_TIME(total3);
total = (end_t-init_t)*1000/CLOCKS_PER_SEC;
fprintf(stderr, "Finish '<' %dms '!=' %dms '--' %dms total:%dms\n", total1, total2, total3, total);
return 0;
}
cmake_minimum_required(VERSION 2.6)
project(test_cpp)
#SET( CMAKE_CXX_COMPILER "/usr/local/bin/g++-9" )
add_definitions(-Wall -W -Wextra -std=c++14 -march=native)
add_executable(test_cpp test.cpp)
#include <stdio.h>
#include <sys/time.h>
#include "../common.h"
#include <valarray>
#include <vector>
#include <unistd.h>
static void operation(int &x){
OPERATION(x);
}
using namespace std;
#define UPDATE_TIME(total) do{ end_t=clock(); total = (end_t - start_t)*1000 / CLOCKS_PER_SEC; start_t=end_t;}while(0)
int main(){
clock_t init_t, start_t, end_t;
int i, k;
volatile int result[SIZE]; //volatile is used to be sure that the compiler execute the calcul.
int tab[SIZE]={0};
valarray<int> array(SIZE);
vector<int> vect(SIZE);
int total1, total2, total3, total4, total5=0, total6=0, total7=0, total_t;
init_t=start_t=clock();
for (k=0; k<TRIALS_NB; k++ ){
for (i=0; i<SIZE; i++){
OPERATION(tab[i]);
}
}
for (int i=0; i<SIZE; i++) result[i]=tab[i];
UPDATE_TIME(total1);
for (k=0; k<TRIALS_NB; k++ ){
for (i=0;i!=SIZE; i++){
OPERATION(tab[i]);
}
}
for (int i=0; i<SIZE; i++) result[i]=tab[i];
UPDATE_TIME(total2);
for (k=0; k<TRIALS_NB; k++ ){
for (i=SIZE-1; i--;){
OPERATION(tab[i]);
}
}
for (int i=0; i!=SIZE; i++) result[i]=tab[i];
UPDATE_TIME(total3);
for (k=0; k<TRIALS_NB; k++ ){
OPERATION(array);
}
for (int i=0; i<SIZE; i++) result[i]=array[i];
UPDATE_TIME(total4);
for (k=0; k<TRIALS_NB; k++ ){
for_each(vect.begin(), vect.end(), operation );
}
for (int i=0; i<SIZE; i++) result[i]=vect[i];
UPDATE_TIME(total5);
for (k=0; k<TRIALS_NB; k++ ){
for_each(vect.begin(), vect.end(), [](int &x){ OPERATION(x);}); //does not work avec xcode ???
}
for (int i=0; i<SIZE; i++) result[i]=vect[i];
UPDATE_TIME(total6);
for (k=0; k<TRIALS_NB; k++ ){
for (int &x : vect) OPERATION(x);
}
for (int i=0; i<SIZE; i++) result[i]=vect[i];
UPDATE_TIME(total7);
total_t = (end_t-init_t)*1000/CLOCKS_PER_SEC;
fprintf(stderr, "Finish c-style: %dms %dms %dms valarray: %dms vector: %dms %dms %dms total:%dms\n", total1, total2, total3, total4, total5, total6, total7, total_t);
return 0;
}