Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
7c41a311
Commit
7c41a311
authored
8 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
added benchmarks to the accuracy test.
parent
32d175ed
No related branches found
No related tags found
1 merge request
!266
Cube root
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/testCbrt.c
+67
-7
67 additions, 7 deletions
tests/testCbrt.c
with
67 additions
and
7 deletions
tests/testCbrt.c
+
67
−
7
View file @
7c41a311
...
...
@@ -25,34 +25,94 @@
// Local includes.
#include
"cbrt.h"
#include
"c
ycle
.h"
#include
"c
locks
.h"
#include
"error.h"
int
main
(
int
argc
,
char
*
argv
[])
{
/* Some constants for this test. */
const
int
num_vals
=
1
000000
;
const
int
num_vals
=
20
000000
;
const
float
range_min
=
-
10
.
0
f
;
const
float
range_max
=
10
.
0
f
;
const
float
err_rel_tol
=
1e-6
;
message
(
"executing %i runs of each command."
,
num_vals
);
/* Create and fill an array of floats. */
float
*
data
=
(
float
*
)
malloc
(
sizeof
(
float
)
*
num_vals
);
for
(
int
k
=
0
;
k
<
num_vals
;
k
++
)
{
data
[
k
]
=
(
float
)
rand
()
/
RAND_MAX
;
data
[
k
]
=
(
1
.
0
f
-
data
[
k
])
*
range_min
+
data
[
k
]
*
range_max
;
}
/* First run just checks for correctnes. */
for
(
int
k
=
0
;
k
<
num_vals
;
k
++
)
{
const
double
exact
=
cbrt
(
data
[
k
]);
// computed in doule just to be sure.
const
double
exact
=
cbrt
(
data
[
k
]);
// computed in doule just to be sure.
const
float
ours
=
1
.
0
f
/
icbrtf
(
data
[
k
]);
const
float
err_abs
=
fabsf
(
exact
-
ours
);
if
(
err_abs
*
fabsf
(
exact
)
>
err_rel_tol
)
{
error
(
"failed for x = %.8e, exact = %.8e, ours = %.8e, err = %.3e.
\n
"
,
data
[
k
],
exact
,
ours
,
err_abs
);
data
[
k
],
exact
,
ours
,
err_abs
);
}
}
/* Second run to check the speed of the inverse cube root. */
float
acc_exact
=
0
.
0
f
;
ticks
tic_exact
=
getticks
();
for
(
int
k
=
0
;
k
<
num_vals
;
k
++
)
{
acc_exact
+=
1
.
0
f
/
cbrtf
(
data
[
k
]);
}
message
(
"1.0f / cbrtf took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_exact
),
clocks_getunit
(),
acc_exact
);
float
acc_ours
=
0
.
0
f
;
ticks
tic_ours
=
getticks
();
for
(
int
k
=
0
;
k
<
num_vals
;
k
++
)
{
acc_ours
+=
icbrtf
(
data
[
k
]);
}
message
(
"icbrtf took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
acc_ours
);
/* Third run to check the speed of the cube root. */
acc_exact
=
0
.
0
f
;
tic_exact
=
getticks
();
for
(
int
k
=
0
;
k
<
num_vals
;
k
++
)
{
acc_exact
+=
cbrtf
(
data
[
k
]);
}
message
(
"cbrtf took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_exact
),
clocks_getunit
(),
acc_exact
);
acc_ours
=
0
.
0
f
;
tic_ours
=
getticks
();
for
(
int
k
=
0
;
k
<
num_vals
;
k
++
)
{
const
float
temp
=
icbrtf
(
data
[
k
]);
acc_ours
+=
data
[
k
]
*
temp
*
temp
;
}
message
(
"x * icbrtf^2 took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
acc_ours
);
/* Fourth run to check the speed of (.)^(2/3). */
acc_exact
=
0
.
0
f
;
tic_exact
=
getticks
();
for
(
int
k
=
0
;
k
<
num_vals
;
k
++
)
{
const
float
temp
=
cbrtf
(
data
[
k
]);
acc_exact
+=
temp
*
temp
;
}
message
(
"cbrtf^2 took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_exact
),
clocks_getunit
(),
acc_exact
);
acc_ours
=
0
.
0
f
;
tic_ours
=
getticks
();
for
(
int
k
=
0
;
k
<
num_vals
;
k
++
)
{
acc_ours
+=
data
[
k
]
*
icbrtf
(
data
[
k
]);
}
message
(
"x * icbrtf took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
acc_ours
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment