Last active
August 29, 2015 14:16
-
-
Save msbaek/4e6db8a3c358170d5262 to your computer and use it in GitHub Desktop.
mean, standard deviation
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
| import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics | |
| import org.scalatest.{FlatSpec, Matchers} | |
| import scala.io.Source | |
| class MobileResponseTimeSpec extends FlatSpec with Matchers { | |
| val FILE_NAME = "/Users/msbaek/Downloads/res_time.txt" | |
| val NINETY = 90.0 | |
| val THREE_SECONDS = 3.0 | |
| val TEN_SECONDS = 10.0 | |
| "90 percentile ResponseTime" should "below 3 seconds" in { | |
| val doubles = Source.fromFile(FILE_NAME).getLines().map(_.toDouble).filter(_ < TEN_SECONDS) | |
| val descriptiveStatistics = new DescriptiveStatistics() | |
| doubles.foreach(descriptiveStatistics.addValue(_)) | |
| printf("mean = %.2f\n", descriptiveStatistics.getMean) | |
| printf("stddev = %.2f\n", descriptiveStatistics.getStandardDeviation) | |
| printf("90p = %.2f\n", descriptiveStatistics.getPercentile(NINETY)) | |
| assert(descriptiveStatistics.getPercentile(NINETY) < THREE_SECONDS) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment