-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_kml_glibc.f90
More file actions
72 lines (62 loc) · 2.07 KB
/
test_kml_glibc.f90
File metadata and controls
72 lines (62 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
! test_kml_glibc.f90
program test_kml_glibc
use kml_interfaces
use, intrinsic :: iso_c_binding, only: c_float, c_double
implicit none
! Declare variables
real(c_float) :: base, exponent, result_kml_pow, result_glibc_pow
real(c_float) :: angle, result_kml_cos, result_glibc_cos
integer :: i, num_tests
real(c_double) :: start_time, end_time, time_kml_pow, time_glibc_pow
real(c_double) :: time_kml_cos, time_glibc_cos
! Random number generator
call random_seed()
! Initialize variables
num_tests = 100000000
! KML pow test
call cpu_time(start_time)
do i = 1, num_tests
call random_number(base)
call random_number(exponent)
base = base * 10.0_c_float
exponent = exponent * 10.0_c_float
result_kml_pow = powf(base, exponent)
end do
call cpu_time(end_time)
time_kml_pow = end_time - start_time
! GLIBC pow test
call cpu_time(start_time)
do i = 1, num_tests
call random_number(base)
call random_number(exponent)
base = base * 10.0_c_float
exponent = exponent * 10.0_c_float
result_glibc_pow = base**exponent
end do
call cpu_time(end_time)
time_glibc_pow = end_time - start_time
! KML cos test
call cpu_time(start_time)
do i = 1, num_tests
call random_number(angle)
angle = angle * 2.0_c_float * 3.14159265358979323846_c_float ! 0 to 2*pi
result_kml_cos = cosf(angle)
end do
call cpu_time(end_time)
time_kml_cos = end_time - start_time
! GLIBC cos test
call cpu_time(start_time)
do i = 1, num_tests
call random_number(angle)
angle = angle * 2.0_c_float * 3.14159265358979323846_c_float ! 0 to 2*pi
result_glibc_cos = cos(angle)
end do
call cpu_time(end_time)
time_glibc_cos = end_time - start_time
! Print results
print *, 'Timing (seconds):'
print *, 'KML pow: ', time_kml_pow
print *, 'GLIBC pow: ', time_glibc_pow
print *, 'KML cos: ', time_kml_cos
print *, 'GLIBC cos: ', time_glibc_cos
end program test_kml_glibc