# FLOAT＆INT speed performance in cuda kernel test 

**URL:** <https://forums.developer.nvidia.com/t/float-int-speed-performance-in-cuda-kernel-test/64941>\
**Category:** DeepStream SDK\
**Created:** [September 10, 2018, 12:12pm UTC](https://forums.developer.nvidia.com/t/float-int-speed-performance-in-cuda-kernel-test/64941 "2018-09-10T12:12:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haifengli](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@haifengli](https://forums.developer.nvidia.com/u/haifengli)\
**Post date:** [September 10, 2018, 12:12pm UTC](https://forums.developer.nvidia.com/t/float-int-speed-performance-in-cuda-kernel-test/64941/1 "2018-09-10T12:12:31Z")

</div>

hello,nvidia

Since I want to know the speed performance between float and int/long type operation in cuda. I made a test program(relese version) like this :

#include \<opencv2/imgproc/imgproc.hpp\>  
#include “opencv2/core.hpp”  
#include \<opencv2/core/utility.hpp\>  
#include “opencv2/highgui.hpp”  
#include “opencv2/cudaarithm.hpp”  
#include “device\_launch\_parameters.h”

#include “cuda\_runtime\_api.h”  
#include “helper\_cuda.h”  
#include \<time.h\>

#define mySIZE 10000

**global** void testFloat()  
{  
float sum = 0.f;  
float tmp = 1.f;  
for (int i = 0; i \< mySIZE; i++)  
{  
sum += (tmp \* i \* 1.123f) / 2.f;

```
}
printf("================%f\n", sum);

```

}

**global** void testInt()  
{  
long long sum = 0;  
long long tmp = 1;

```
for (int i = 0; i < mySIZE; i++)
{
	sum += (tmp * i * 1.123f ) / 2.f;

}
printf("+++++++++++++++++%lld\n", sum);

```

}

int main()  
{

```
time_t str = clock();
testFloat << <1, 1 >> > ();
cudaDeviceSynchronize();

time_t end = clock();

printf("float time%fms\n", (double)(end - str) / 1000.f);

time_t str1 = clock();
testInt << <1, 1 >> > ();
cudaDeviceSynchronize();

time_t end1 = clock();

printf("long time%fms\n", (double)(end1 - str1) / 1000.f);

return 0;

```

}

do 10000 times add operation including muliply & divsion. And in case of speed optimazition, I printed the result finally.

but I feel the way to test is not correct. the FLOAT fast than INT 200 times. did I test correctly？

and the result:  
================28072190.000000  
float time248.643000ms  
+++++++++++++++++28070078  
long time0.902000ms

nvidia card P4

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [September 11, 2018, 5:50am UTC](https://forums.developer.nvidia.com/t/float-int-speed-performance-in-cuda-kernel-test/64941/2 "2018-09-11T05:50:38Z")

</div>

Hi,

Some issue from _testInt_ function:

```auto
sum += (tmp * i * 1.123f ) / 2.f;

```

The result is multiplied/divided with a float number.  
The temporal results will be stored in the float format and rounded into integer in the end.

If you want to test an integer calculation, it’s recommended to use integer multiplier and divider.

Thanks.

---

<div class="post-metadata">

**Author:** ![haifengli](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@haifengli](https://forums.developer.nvidia.com/u/haifengli)\
**Post date:** [September 11, 2018, 7:30am UTC](https://forums.developer.nvidia.com/t/float-int-speed-performance-in-cuda-kernel-test/64941/3 "2018-09-11T07:30:21Z")

</div>

We’ll update our test code with you comment.

Thanks.
