output(floatingPointAdditionSubtractionSpeed,"floating point addition subtraction");
output(floatingPointMultiplicationSpeed,"floating point multiplication");
output(floatingPointDivisionSpeed,"floating point division");
output(analogReadSpeed,"analog read");
output(primeSieveSpeed,"prime calculation");
Serial.println("Done.");
}
voidloop(){}
/*
int testEepromWrite(){
for (int i = 0; i < 512; i++){
EEPROM.write(i, 0);
}
int startVal = millis();
for(int i = 0; i < 512; i++){
EEPROM.write(i, 1);
}
int endVal = millis();
return endVal-startVal;
}
int testEepromRead(){
int val;
int startVal = millis();
for(int i = 0; i < 2000; i++){
for(int i = 0; i < 512; i++){
val = EEPROM.read(i);
}
}
int endVal = millis();
return endVal-startVal;
}
*/
inttestIntegerAdditionSubtraction(){
intvolatileval;
inti;
intk;
intstartVal=millis();
for(intj=0;j<10;j++){
for(i=0;i<10000;i++){
val=i+42;
}
for(k=0;k<10000;k++){
val=k-42;
}
val=0;
}
intendVal=millis();
returnendVal-startVal;
}
inttestIntegerMultiplication(){
intvolatileval;
inti;
intk;
intstartVal=millis();
for(intj=0;j<10;j++){
for(i=0;i<10000;i++){
val=i*42;
}
for(k=0;k<10000;k++){
val=k*42;
}
val=0;
}
intendVal=millis();
returnendVal-startVal;
}
inttestIntegerDivision(){
intvolatileval;
inti;
intk;
intstartVal=millis();
for(intj=0;j<10;j++){
for(i=0;i<10000;i++){
val=i/42;
}
for(k=0;k<10000;k++){
val=k/42;
}
val=0;
}
intendVal=millis();
returnendVal-startVal;
}
inttestFloatingPointAdditionSubtraction(){
floatvolatileval=42.4242;
intj;
inti;
intstartVal=millis();
for(j=0;j<10;j++){
for(i=0;i<10000;i++){
val=val+i;
val=42.4242;
}
for(intk=0;k<10000;k++){
val=val-k;
val=42.4242;
}
}
intendVal=millis();
returnendVal-startVal;
}
inttestFloatingPointMultiplication(){
floatvolatileval=42.4242;
intj;
inti;
intstartVal=millis();
for(j=0;j<10;j++){
for(i=0;i<10000;i++){
val=val*i;
val=val*i;
val=42.4242;
}
}
intendVal=millis();
returnendVal-startVal;
}
inttestFloatingPointDivision(){
floatvolatileval=42.4242;
intj;
inti;
intstartVal=millis();
for(j=0;j<10;j++){
for(i=0;i<10000;i++){
val=i/val;
val=i/val;
val=42.4242;
}
}
intendVal=millis();
returnendVal-startVal;
}
inttestAnalogRead(){
doublevolatileval;
intstartVal=millis();
for(inti=0;i<5000;i++){
val=analogRead(1);
val=analogRead(1);
}
intendVal=millis();
returnendVal-startVal;
}
inttestPrimeSievev1(){
intstartTime=micros();//record the current system time in the long variable time (for benchmarking purposes)
intmaxNumber=MAX_PRIME_V1;//takes an input from the user and stores it in the maxNumber variable, this variable is the maximum number that this program will compute primes up to
//boolean[] booleanIsItPrimeArray = new boolean[maxNumber + 1]; //the IsItPrimeArray is used to store whether a specific number is prime
booleanbooleanIsItPrimeArray[maxNumber+1];
for(inti=2;i<=maxNumber;i++){//starts at 2 and sets all of the values in the array to true
booleanIsItPrimeArray[i]=true;
}
for(inti=2;i<=sqrt(maxNumber);i++){// i serves as what you are testing (first 2, then 3, then 5, then 7...)
if(booleanIsItPrimeArray[i]==true){
for(intj=i;i*j<=maxNumber;j++){//j is set equal to i (set to 2, then 3, then 5, then 7) and while i*j is less than the max number it continues
/*
* Explanation of the above two lines of code:
* -the first line serves as what multiple it is crossing off (first 2, then 3, then 5, then 7...)
* -the second line will be explained later
* -the third line serves to have it actually do the multiplication so to speak
* -it first checks if i (the multiple) times j (what we're multiplying it by) is less than or equal to maxNumber, if it is than it continues
* -it then crosses out that number by setting that location in the booleanIsItPrimeArray to false
* -once the second line loop finishes, then it goes to the above for loop and moves onto the next multiple, 3
* -if that multiple has already been set to false, (e.g. 4 would already be set to false because it is a multiple of 2), then it does not continue
* -thus if it is already false then it will loop back and try the next multiple
* -it will then continue this behavior until it reaches maxNumber, at which point it has crossed out all of the non-primes
*/
booleanIsItPrimeArray[i*j]=false;//false means it is not a prime (effectively crossing it out)
//Serial.println("Debug: setting to false"); //for debugging purposes
}
}
}
//Serial.println("1"); //prints out 1 (since this method does not account for 1 I just manually print it out)
intprime=0;//used in calculating how many primes I calculated
for(inti=2;i<maxNumber;i++){//starts at 2 and counts up to max number
if(booleanIsItPrimeArray[i]==true){//if that spot is not 0, then continue
//Serial.println(i); //prints out the prime number