|
Rube Goldberg Machine 1.0
This is the base code for Rube Goldberg designed for the CS296 Software Systems Lab
|
#include <iostream>#include "render.hpp"#include "cs296_base.hpp"#include "callbacks.hpp"#include <sys/time.h>#include "GL/glui.h"#include <cstdio>
Go to the source code of this file.
Namespaces | |
| namespace | cs296 |
These are user defined include files Included in double quotes - the path to find these has to be given at compile time. | |
Functions | |
| void | average_time (int32 no_of_steps) |
| Function to compute the average time for 100 iterations. | |
| int | main (int argc, char **argv) |
| This is the main function. | |
| void average_time | ( | int32 | no_of_steps | ) |
Function to compute the average time for 100 iterations.
Used to determine duration of function calls.
Definition at line 69 of file main.cpp.
{
// settings_hz from callbacks.cpp
float32 step_size=1/settings_hz;
b2World* world = test->get_world();
const b2Profile& world_profile = world->GetProfile();
int32 step_Count=0;
float32 time_taken_for_step=0.0000;
float32 time_taken_for_velocity_update=0.0000;
float32 time_taken_for_collisions=0.0000;
float32 time_taken_for_position_update=0.0000;
struct timeval start, end;
gettimeofday(&start,NULL);
double t1 = 1000*(start.tv_sec) + start.tv_usec/1000.0;
while (step_Count<no_of_steps)
{
// Step function for Simulation in Box2D world.
world->Step(step_size, settings.velocity_iterations, settings.position_iterations);
time_taken_for_step +=world_profile.step;
time_taken_for_velocity_update += world_profile.solveVelocity;
time_taken_for_collisions += world_profile.collide;
time_taken_for_position_update += world_profile.solvePosition;
step_Count++;
}
gettimeofday(&end, NULL);
double t2 = 1000*(end.tv_sec) + end.tv_usec/1000.0;
double t= t2 - t1;
//[Lab07]
std::cout<<"Total Iterations: "<< no_of_steps<<"\n";
std::cout<<"Average time per step is "<< time_taken_for_step/no_of_steps<<" ms\n";
std::cout<<"Average time for collisions is "<<time_taken_for_collisions/no_of_steps<<" ms\n";
std::cout<<"Average time for velocity updates is "<<time_taken_for_velocity_update/no_of_steps<<" ms\n";
std::cout<<"Average time for position updates is "<<time_taken_for_position_update/no_of_steps<<" ms\n\n";
std::cout<<"Total time for loop is "<<t<<" ms"<<std::endl;
//std::cout <<t/1000
//<<std::endl;
}
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
This is the main function.
[Lab05] Computing average time for no_of_steps iterations:
Definition at line 115 of file main.cpp.
{
test_count = 1;
test_index = 0;
test_selection = test_index;
entry = sim;
test = entry->create_fcn();
// Command Line argument for number of iterations
int no_of_steps = 0;
if(argc == 1) no_of_steps = 100; //Default Value
else no_of_steps = atoi(argv[1]);
average_time(no_of_steps);
return 0;
}
1.7.4