#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

Similar to timingExercise (20)

PDF
I have written the code but cannot complete the assignment please help.pdf
PPT
lecture56functionsggggggggggggggggggg.ppt
PPT
lecture56.ppt
DOCX
Assignment 3
DOCX
@author Jane Programmer @cwid 123 45 678 @class.docx
PDF
Objectives 1. using indirect addressing 2. passing parameters.pdf
DOCX
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
PPTX
Random numbers c++ class 11 and 12
DOCX
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docx
PDF
3. Implement the UnsortedList class to store a list of numbers that .pdf
PPTX
Time and Space Complexity Analysis.pptx
DOCX
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
TXT
Simulador carrera de caballos desarrollado en C++
PDF
C++You will design a program to play a simplified version of war, .pdf
PPTX
MUST CS101 Lab11
TXT
Bb2
PDF
c++ exp 1 Suraj...pdf
PDF
02 analysis
PDF
maXbox Blix the Programmer
I have written the code but cannot complete the assignment please help.pdf
lecture56functionsggggggggggggggggggg.ppt
lecture56.ppt
Assignment 3
@author Jane Programmer @cwid 123 45 678 @class.docx
Objectives 1. using indirect addressing 2. passing parameters.pdf
Lab01Filesbuild.bat@echo offclsset DRIVE_LETTER=1.docx
Random numbers c++ class 11 and 12
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docx
3. Implement the UnsortedList class to store a list of numbers that .pdf
Time and Space Complexity Analysis.pptx
ECS 60 Programming Assignment #1 (50 points) Winter 2016 .docx
Simulador carrera de caballos desarrollado en C++
C++You will design a program to play a simplified version of war, .pdf
MUST CS101 Lab11
Bb2
c++ exp 1 Suraj...pdf
02 analysis
maXbox Blix the Programmer

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; }