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
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
17 allocate(search_vals(n_finds))
19 print *,
"Number of lookups: ", n_finds
21 print *,
"Test size | correct? | t_linear | t_bsearch | t_adaptive"
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
29 call random_number(list)
32 list(i) = list(i-1) + list(i)
35 call cpu_time(t_start)
40 t_linear = t_end - t_start
42 call cpu_time(t_start)
47 t_bsearch = t_end - t_start
49 call cpu_time(t_start)
54 t_adaptive = t_end - t_start
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
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,...