# Why is SURF slower than SIFT when I use features2d to accomplish this two algorithms?

**URL:** <https://forum.opencv.org/t/why-is-surf-slower-than-sift-when-i-use-features2d-to-accomplish-this-two-algorithms/7968>\
**Category:** Python\
**Tags:** features2d\
**Created:** [March 16, 2022, 8:34am UTC](https://forum.opencv.org/t/why-is-surf-slower-than-sift-when-i-use-features2d-to-accomplish-this-two-algorithms/7968 "2022-03-16T08:34:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![li\_fan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/li_fan/32/4750_2.png) [@li\_fan](https://forum.opencv.org/u/li_fan)\
**Post date:** [March 16, 2022, 8:34am UTC](https://forum.opencv.org/t/why-is-surf-slower-than-sift-when-i-use-features2d-to-accomplish-this-two-algorithms/7968/1 "2022-03-16T08:34:51Z")

</div>

Hi! i just met a doubting question…my code is this:

```auto
import numpy as np
import cv2
import matplotlib.pyplot as plt
import time

print("debug")

img1 = cv2.imread('rubberwhale1.png',0) # queryImage

surf = cv2.xfeatures2d_SURF.create()

tic = time.time()
kp = surf.detect(img1)
toc = time.time()
print(f'The total time of the SURF is：：' + str(float(toc - tic)))

sift = cv2.xfeatures2d_SIFT.create()
tic = time.time()

kp = sift.detect(img1)

toc = time.time()
print(f'The total time of the SIFT is：' + str(float(toc - tic)))

```

i run this script,and i get result like this(i tested many types imgs):

> The total time of the SURF is：：1.225409984588623  
> The total time of the SIFT is：0.03789663314819336

By the way,my opencv-python == 3.4.2.16 opencv-contrib-python== 3.4.2.16.

as i know ，surf should be much faster than sift, why am I getting this result?

---

<div class="post-metadata">

**Author:** ![li\_fan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/li_fan/32/4750_2.png) [@li\_fan](https://forum.opencv.org/u/li_fan)\
**Post date:** [March 16, 2022, 12:04pm UTC](https://forum.opencv.org/t/why-is-surf-slower-than-sift-when-i-use-features2d-to-accomplish-this-two-algorithms/7968/2 "2022-03-16T12:04:09Z")

</div>

who can help me,i will very appreciate he/she! this question confuses me very much:dizzy\_face:

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 16, 2022, 12:46pm UTC](https://forum.opencv.org/t/why-is-surf-slower-than-sift-when-i-use-features2d-to-accomplish-this-two-algorithms/7968/3 "2022-03-16T12:46:02Z")

</div>

reorder your code.

1. initialize both
2. run both once on the data
3. now measure time of multiple runs of each

and you might wanna use `time.perf_counter()` for time differences. that is the highest precision clock available.

---

<div class="post-metadata">

**Author:** ![li\_fan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/li_fan/32/4750_2.png) [@li\_fan](https://forum.opencv.org/u/li_fan)\
**Post date:** [March 16, 2022, 2:32pm UTC](https://forum.opencv.org/t/why-is-surf-slower-than-sift-when-i-use-features2d-to-accomplish-this-two-algorithms/7968/5 "2022-03-16T14:32:57Z")

</div>

Thank u very much!!! you are right,I have verified that SURF is faster than SIFT,although i didn’t see SURF is threes times than SIFT,but i think it’s maybe parameters problem.thank you again!

---

<div class="post-metadata">

**Author:** ![li\_fan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/li_fan/32/4750_2.png) [@li\_fan](https://forum.opencv.org/u/li_fan)\
**Post date:** [March 16, 2022, 2:43pm UTC](https://forum.opencv.org/t/why-is-surf-slower-than-sift-when-i-use-features2d-to-accomplish-this-two-algorithms/7968/6 "2022-03-16T14:43:11Z")

</div>

With crackwitz’s help,i successed clear up my doubts,this is my code:

```auto
import cv2
import time

img1 = cv2.imread('lena.jpg',0)         

# 1.init
#surf = cv2.xfeatures2d_SURF.create()
#sift = cv2.xfeatures2d_SIFT.create()
surf = cv2.xfeatures2d.SURF_create(400)
sift = cv2.xfeatures2d.SIFT_create()

total_time = 0
experiment_times = 1
for i in range(experiment_times):
    tic = time.perf_counter()
    kp = surf.detect(img1)
    toc = time.perf_counter()
    total_time +=(toc - tic)
print(f'The mean time of the SURF is：：' + str(float(total_time / experiment_times)))

total_time = 0
for i in range(experiment_times):
    tic = time.perf_counter()
    kp = sift.detect(img1)
    toc = time.perf_counter()
    total_time +=(toc - tic)

print(f'The mean time of the SIFT is：' + str(float(total_time / experiment_times)))

```

lena.jpg from opencv/sources/samples/data.  
when experiment\_times = 1,i got:

```auto
The mean time of the SURF is：：1.3295887999999998
The mean time of the SIFT is：0.03701199999999982

```

when experiment\_times = 3,i got:

```auto
The mean time of the SURF is：：0.4178568333333334
The mean time of the SIFT is：0.03863946666666666

```

when experiment\_times = 10,i got:

```auto
The mean time of the SURF is：：0.14091486000000003
The mean time of the SIFT is：0.037559639999999915

```

when experiment\_times = 100,i got:

```auto
The mean time of the SURF is：：0.03580691399999997
The mean time of the SIFT is：0.04023345399999998

```

when experiment\_times = 300,i got:

```auto
The mean time of the SURF is：：0.028634289333333295
The mean time of the SIFT is：0.04184386500000007

```

when experiment\_times = 500,i got:

```auto
The mean time of the SURF is：：0.026373681000000048
The mean time of the SIFT is：0.04070335280000003

```

if i dont sent 400 to SURF\_create,just use :`surf = cv2.xfeatures2d.SURF_create()`,i got:

```auto
experiment_times = 1
The mean time of the SURF is：：1.2036111

experiment_times = 3
The mean time of the SURF is：：0.4234273333333333

experiment_times = 10
The mean time of the SURF is：：0.14784130999999998

experiment_times = 100
The mean time of the SURF is：：0.03896763600000006

experiment_times = 300
The mean time of the SURF is：：0.032780147666666676

```

just writing about the experiment in the hope that it will help others who have doubts 😁
