mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-30 08:44:37 +00:00
tests/invalid/*.{m,err_exp}:
tests/misc_tests/*.m:
tests/mmc_make/*.m:
tests/par_conj/*.m:
tests/purity/*.m:
tests/stm/*.m:
tests/string_format/*.m:
tests/structure_reuse/*.m:
tests/submodules/*.m:
tests/tabling/*.m:
tests/term/*.m:
tests/trailing/*.m:
tests/typeclasses/*.m:
tests/valid/*.m:
tests/warnings/*.{m,exp}:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the tests
that check compiler error messages, expect the new line numbers.
browser/cterm.m:
browser/tree234_cc.m:
Import only one module per line.
tests/hard_coded/boyer.m:
Fix something I missed.
84 lines
2.0 KiB
Mathematica
84 lines
2.0 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
:- module fib_float.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is cc_multi.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module benchmarking.
|
|
:- import_module float.
|
|
:- import_module int.
|
|
:- import_module require.
|
|
|
|
:- pragma require_feature_set([memo]).
|
|
|
|
main(!IO) :-
|
|
perform_trials(20.0, !IO).
|
|
|
|
:- pred perform_trials(float::in, io::di, io::uo) is cc_multi.
|
|
|
|
perform_trials(N, !IO) :-
|
|
trial(N, Time, MTime),
|
|
% io__write_float(N, !IO),
|
|
% io__write_string(": ", !IO),
|
|
% io__write_int(Time, !IO),
|
|
% io__write_string("ms vs ", !IO),
|
|
% io__write_int(MTime, !IO),
|
|
% io__write_string("ms\n", !IO),
|
|
(
|
|
(
|
|
Time > 10 * MTime,
|
|
MTime > 0 % untabled takes ten times as long
|
|
;
|
|
Time > 100, % untabled takes at least 100 ms
|
|
MTime < 1 % while tabled takes at most 1 ms
|
|
)
|
|
->
|
|
io__write_string("tabling works\n", !IO)
|
|
;
|
|
Time > 10000 % untabled takes at least 10 seconds
|
|
->
|
|
io__write_string("tabling does not appear to work\n", !IO)
|
|
;
|
|
% We couldn't get a measurable result with N,
|
|
% and it looks like we can afford a bigger trial
|
|
perform_trials(N + 3.0, !IO)
|
|
).
|
|
|
|
:- pred trial(float::in, int::out, int::out) is cc_multi.
|
|
|
|
trial(N, Time, MTime) :-
|
|
benchmark_det(fib, N, Res, 1, Time),
|
|
benchmark_det(mfib, N, MRes, 1, MTime),
|
|
require(unify(Res, MRes), "tabling produces wrong answer").
|
|
|
|
:- pred fib(float::in, float::out) is det.
|
|
|
|
fib(N, F) :-
|
|
( N < 2.0 ->
|
|
F = 1.0
|
|
;
|
|
fib(N - 1.0, F1),
|
|
fib(N - 2.0, F2),
|
|
F = F1 + F2
|
|
).
|
|
|
|
:- pred mfib(float::in, float::out) is det.
|
|
:- pragma memo(mfib/2).
|
|
|
|
mfib(N, F) :-
|
|
( N < 2.0 ->
|
|
F = 1.0
|
|
;
|
|
mfib(N - 1.0, F1),
|
|
mfib(N - 2.0, F2),
|
|
F = F1 + F2
|
|
).
|