Created
September 9, 2016 19:30
-
-
Save theapache64/ff6afe608eae76237db12b7057f7f720 to your computer and use it in GitHub Desktop.
Speeder test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lab; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
/** | |
* Created by theapache64 on 27/8/16. | |
*/ | |
public class Main { | |
private static final int START = 1; | |
private static final int END = 100; | |
private static final int DURATION = 1000; | |
public static void main(String[] args) throws IOException, InterruptedException { | |
final Speeder speeder = new Speeder(START, END, DURATION); | |
final long startTime = System.currentTimeMillis(); | |
double totalTime = 0; | |
for (int i = START; i < END; i++) { | |
double sleepTime = speeder.getSpeed(i); | |
totalTime += sleepTime; | |
System.out.println("\r" + i + " - " + sleepTime); | |
Thread.sleep(Math.round(sleepTime)); | |
} | |
System.out.println(); | |
System.out.println("Total sleep time : " + totalTime); | |
System.out.println("Balance : " + (DURATION - totalTime)); | |
//System.out.println("Took : " + (System.currentTimeMillis() - startTime) + "ms"); | |
} | |
public static class Speeder { | |
public final int start, end, duration; | |
private final double speeder; | |
public Speeder(int start, int end, int duration) { | |
this.start = start; | |
this.end = end; | |
this.duration = duration; | |
this.speeder = (double) (DURATION / END) * 2 + (double) DURATION / 4949; | |
} | |
public double getSpeed(final int i) { | |
return speeder * i / END; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment