

#include "bits/fibrep.h"

#include "bits/printbin.h"  // print_bin()
#include "fxtiomanip.h"

#include "demo/nextarg.h"
#include "fxttypes.h"  // ulong
#include "bits/bitsperlong.h"

#include "jjassert.h"


//% Fibonacci representations: successive generation.


//#define TIMING // uncomment to disable printing

int
main(int argc, char **argv)
{
    ulong n = 7;
    NXARG(n, "Number of bits");
    jjassert( n<BITS_PER_LONG );
    bool fq = 1;
    NXARG(fq, "Whether to use increasing order");

    ulong ct = 0;


    if ( fq )
    {
        const ulong f = 1UL << n;
        ulong t = 0;
        do
        {
#ifndef TIMING
            cout << setw(4) << ct;
            print_bin(": ", t, n);
            cout << endl;
#endif
            ++ct;
            t = next_fibrep(t);
        }
        while ( t!=f );
    }
    else
    {
        ulong f = 1UL << n;
        do
        {
            f = prev_fibrep(f);
#ifndef TIMING
            cout << setw(4) << ct;
            print_bin(": ", f, n);
            cout << endl;
#endif
            ++ct;
        }
        while ( f );
    }

    cout << "ct=" << ct << endl;

    return 0;
}
// -------------------------

/*
Timing:

forward:
% time ./bin 40 1
arg 1: 40 == n  [Number of bits]  default=7
arg 2: 1 == fq  [Whether to use increasing order]  default=1
ct=267914296
./bin 40 1  1.47s user 0.00s system 100% cpu 1.466 total
 ==> 267914296/1.47 == 182,254,623 per second
%
% time ./bin 44 1
arg 1: 44 == n  [Number of bits]  default=7
arg 2: 1 == fq  [Whether to use increasing order]  default=1
ct=1836311903
./bin 44 1  10.02s user 0.00s system 100% cpu 10.022 total
 ==> 1836311903/10.02 == 183,264,660 per second

BENCHARGS=44 1
BENCHARGS=44 0


backward, with version 3 (default) in fibrep.h:
% time ./bin 40 0
arg 1: 40 == n  [Number of bits]  default=7
arg 2: 0 == fq  [Whether to use increasing order]  default=1
ct=267914296
./bin 40 0  1.59s user 0.00s system 100% cpu 1.588 total
 ==> 267914296/1.59 == 168,499,557 per second
%
% time ./bin 44 0
arg 1: 44 == n  [Number of bits]  default=7
arg 2: 0 == fq  [Whether to use increasing order]  default=1
ct=1836311903
./bin 44 0  10.82s user 0.03s system 100% cpu 10.841 total
 ==> 1836311903/10.82 == 169,714,593 per second

backward, with version 1 in fibrep.h:
% time ./bin 40 0
arg 1: 40 == n  [Number of bits]  default=7
arg 2: 0 == fq  [Whether to use increasing order]  default=1
ct=267914296
./bin 40 0  1.96s user 0.01s system 99% cpu 1.963 total
 ==> 267914296/1.96 == 136,690,967 per second

backward, with version 2 in fibrep.h:
% time ./bin 40 0
arg 1: 40 == n  [Number of bits]  default=7
arg 2: 0 == fq  [Whether to use increasing order]  default=1
ct=267914296
./bin 40 0  2.56s user 0.01s system 99% cpu 2.576 total
 ==> 267914296/2.56 == 104,654,021 per second

*/


/// Emacs:
/// Local Variables:
/// MyRelDir: "demo/bits"
/// makefile-dir: "../../"
/// make-target: "1demo DSRC=demo/bits/fibrep2-demo.cc"
/// make-target2: "1demo DSRC=demo/bits/fibrep2-demo.cc DEMOFLAGS=-DTIMING"
/// End:

