My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

67 lines
2.2 KiB

#include <iostream>
#include <ctime>
#include <valarray>
#include "Attractor.hpp"
#include "Canvas.hpp"
#include "Projector.hpp"
#include "defines.hpp"
/*
I compared the performance of C-style arrays with valarray. My conclusion is that accessing and setting elements makes no difference (sometimes C-syle array's were just 2% faster, but sometimes valarray was 2% faster (5000000 samples)). But the allocation and initialisation of the valrray was like 30% faster, so it might be a good idea to change my C-style array to valarray. It is also nicer in use, one can use functions like sum, etc. How valarray manages memory may also be more efficient, but all i know is that a valarray<double> is bigger than a double* (in means of sizeof()), but that is not really an issue. So valarray!!!
*/
int main(int argc, char *argv[]) {
clock_t start, end;
double totalTime, totalIterations;
bool verbose = false;
// initialising stuff
Attractor myAttractor(ATTRACTOR_FILE);
Projector projection;
Canvas canvas(WIDTH, HEIGHT, 3);
projection.canvas = &canvas;
myAttractor.projectors.push_back(&projection);
myAttractor.init_range();
projection.output();
unsigned int iterations = ITERATIONS;
start = clock();
for ( unsigned int j = 1; j <= 100; j++ ) {
for ( unsigned int i = 0; i <= iterations; i++ ) {
myAttractor.iterate();
myAttractor.plot();
}
if (verbose) {
myAttractor.output();
std::cout << j << "% done" << std::endl;
}
}
end = clock();
totalIterations = 100.0*iterations;
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
std::cout << std::endl << "total clock time: " << totalTime << std::endl;
std::cout << "average iterations per second: " << totalIterations/((double)(end-start)/(double)(CLOCKS_PER_SEC)) << std::endl << std::endl;
// saving output
start = clock();
canvas.output_file();
end = clock();
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
std::cout << "total clock time for writing png: " << totalTime << std::endl;
std::cout << std::endl << "Awesome Attractor, version " << __DATE__ << std::endl;
return 0;
}