SlideShare a Scribd company logo
#include<random>
#include<forward_list>
#include<chrono>
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
bool runLoop = true;
int n = 0;
forward_list<int> randList;
while(runLoop)
{
// Get n from user -- This tells us the # of times to loop
cout << "Enter n: ";
cin >> n;
// Check n to b valid. while n <=0, keep looping
while (n <= 0)
{
cout << "ERROR! n has to be greater than 1. Enter n: ";
cin >> n;
}
cout << "Start Clock";
default_random_engine generator; // c++.com random 111
uniform_int_distribution<int> distribution(-1000,1000);// 111
// Get start time
steady_clock::time_point startTime = steady_clock::now(); //
chrono steady_clock 22
// Loop n times
for (int i=0; i<n; i++)
{
// Get random # & insert to forward_list
int dice_roll = distribution(generator); // 111
randList.insert(dice_roll);
}
// get end time
steady_clock::time_point t2 = steady_clock::now(); // 22
duration<double> time_span =
duration_cast<duration<double>>(t2 - t1); // 22
// report total time (endTime - startTime) & n
cout << "It took me " << time_span.count() << " seconds to
loop " << n << " times." << endl; // 22
cout << "0 to quit n 1 to continue: ";
cin >> runLoop;
}
return 0;
}

More Related Content

PPT
Loops (1)
PDF
3 rd animation
PDF
JavaSE7 Launch Event: Java7xGroovy
PDF
DOC
VLSI Sequential Circuits II
TXT
Snake.c
PDF
Why is a[1] fast than a.get(1)
DOCX
Java Code for Sample Projects Methods
Loops (1)
3 rd animation
JavaSE7 Launch Event: Java7xGroovy
VLSI Sequential Circuits II
Snake.c
Why is a[1] fast than a.get(1)
Java Code for Sample Projects Methods

What's hot (20)

PDF
Libtcc and gwan
PDF
Data structure programs in c++
DOCX
Jose dossantos.doc
PDF
Go Containers
DOCX
Jarmo van de Seijp Shadbox ERC223
PDF
Playing 44CON CTF for fun and profit
PDF
Building a DSL with GraalVM (VoxxedDays Luxembourg)
PDF
Async Microservices with Twitter's Finagle
DOCX
Doubly linklist
PPT
PDF
All I know about rsc.io/c2go
PDF
Reactive x
PDF
How to install a personal condor
PPTX
Queue oop
PDF
JavaScript - Agora nervoso
PDF
Concurrency in Golang
PDF
Inteligencia artificial 11
DOCX
Cpp programs
Libtcc and gwan
Data structure programs in c++
Jose dossantos.doc
Go Containers
Jarmo van de Seijp Shadbox ERC223
Playing 44CON CTF for fun and profit
Building a DSL with GraalVM (VoxxedDays Luxembourg)
Async Microservices with Twitter's Finagle
Doubly linklist
All I know about rsc.io/c2go
Reactive x
How to install a personal condor
Queue oop
JavaScript - Agora nervoso
Concurrency in Golang
Inteligencia artificial 11
Cpp programs
Ad

Similar to timingExercise (20)

PDF
4th_Ed_Ch03.pdf
PPTX
Oop object oriented programing topics
PDF
Programming Fundamentals presentation slide
DOCX
@author Jane Programmer @cwid 123 45 678 @class.docx
DOCX
PPTX
Computational Physics Cpp Portiiion.pptx
PPT
FP 201 - Unit 3 Part 2
DOCX
C++ file
DOCX
C++ file
PPTX
Loop control structure
PPT
06 Loops
DOCX
#include customer.h#include heap.h#include iostream.docx
PDF
I have written the code but cannot complete the assignment please help.pdf
PPTX
Computational PhysicsssComputational Physics.pptx
DOCX
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
PPTX
MUST CS101 Lab11
PPTX
Pointers in c++ programming presentation
PDF
54602399 c-examples-51-to-108-programe-ee01083101
PPTX
Lec7 - Loops updated.pptx
PPTX
06.Loops
4th_Ed_Ch03.pdf
Oop object oriented programing topics
Programming Fundamentals presentation slide
@author Jane Programmer @cwid 123 45 678 @class.docx
Computational Physics Cpp Portiiion.pptx
FP 201 - Unit 3 Part 2
C++ file
C++ file
Loop control structure
06 Loops
#include customer.h#include heap.h#include iostream.docx
I have written the code but cannot complete the assignment please help.pdf
Computational PhysicsssComputational Physics.pptx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
MUST CS101 Lab11
Pointers in c++ programming presentation
54602399 c-examples-51-to-108-programe-ee01083101
Lec7 - Loops updated.pptx
06.Loops
Ad

timingExercise

  • 1. #include<random> #include<forward_list> #include<chrono> #include<iostream> #include<ctime> #include<cstdlib> using namespace std; int main() { bool runLoop = true; int n = 0; forward_list<int> randList; while(runLoop) { // Get n from user -- This tells us the # of times to loop cout << "Enter n: "; cin >> n; // Check n to b valid. while n <=0, keep looping while (n <= 0) { cout << "ERROR! n has to be greater than 1. Enter n: "; cin >> n; } cout << "Start Clock"; default_random_engine generator; // c++.com random 111 uniform_int_distribution<int> distribution(-1000,1000);// 111 // Get start time steady_clock::time_point startTime = steady_clock::now(); // chrono steady_clock 22 // Loop n times for (int i=0; i<n; i++) { // Get random # & insert to forward_list int dice_roll = distribution(generator); // 111 randList.insert(dice_roll); } // get end time steady_clock::time_point t2 = steady_clock::now(); // 22 duration<double> time_span = duration_cast<duration<double>>(t2 - t1); // 22 // report total time (endTime - startTime) & n cout << "It took me " << time_span.count() << " seconds to loop " << n << " times." << endl; // 22 cout << "0 to quit n 1 to continue: "; cin >> runLoop; } return 0; }