afivo-streamer 1.1
1D/2D/3D streamer simulations with AMR
Loading...
Searching...
No Matches
test_find_index_performance.f90
Go to the documentation of this file.
3 implicit none
4
5 integer, parameter :: dp = kind(0.0d0)
6 integer, parameter :: min_size = 10
7 integer, parameter :: max_size = 100
8 integer, parameter :: delta_size = 10
9 integer, parameter :: n_finds = 1000*1000
10
11 integer :: i, ix_1, ix_2, ix_3, test_size, n
12 real(dp), allocatable :: list(:)
13 real(dp), allocatable :: search_vals(:)
14 real(dp) :: t_start, t_end, t_linear
15 real(dp) :: t_bsearch, t_adaptive
16
17 allocate(search_vals(n_finds))
18
19 print *, "Number of lookups: ", n_finds
20 print *, ""
21 print *, "Test size | correct? | t_linear | t_bsearch | t_adaptive"
22
23 do test_size = min_size, max_size, delta_size
24 allocate(list(test_size))
25 call random_number(search_vals)
26 search_vals = search_vals * test_size
27
28 ! Create sorted list
29 call random_number(list)
30 list = nint(list)
31 do i = 2, test_size
32 list(i) = list(i-1) + list(i)
33 end do
34
35 call cpu_time(t_start)
36 do n = 1, n_finds
37 ix_1 = find_index_linear(list, search_vals(n))
38 end do
39 call cpu_time(t_end)
40 t_linear = t_end - t_start
41
42 call cpu_time(t_start)
43 do n = 1, n_finds
44 ix_2 = find_index_bsearch(list, search_vals(n))
45 end do
46 call cpu_time(t_end)
47 t_bsearch = t_end - t_start
48
49 call cpu_time(t_start)
50 do n = 1, n_finds
51 ix_3 = find_index_adaptive(list, search_vals(n))
52 end do
53 call cpu_time(t_end)
54 t_adaptive = t_end - t_start
55
56 write(*, '(i9,l10,3e12.2)') test_size, &
57 ix_1 == ix_2 .and. ix_2 == ix_3, &
58 t_linear, t_bsearch, t_adaptive
59 deallocate(list)
60 end do
61
62end program performance_test
A Fortran 90 module for creating lookup tables. These tables can be used to efficiently interpolate o...
pure integer function, public find_index_bsearch(list, val)
Binary search of sorted list for the smallest ix such that list(ix) >= val. On failure,...
pure integer function, public find_index_adaptive(list, val)
Adaptive search (combination of linear and binary search) of sorted list for the smallest ix such tha...
pure integer function, public find_index_linear(list, val)
Linear search of sorted list for the smallest ix such that list(ix) >= val. On failure,...
program performance_test