Skip to content

Commit

Permalink
更新自 develop
Browse files Browse the repository at this point in the history
  • Loading branch information
blinkfox committed Jun 7, 2020
2 parents 171e8fe + f2edfee commit bf9757e
Show file tree
Hide file tree
Showing 49 changed files with 2,920 additions and 1,052 deletions.
323 changes: 236 additions & 87 deletions README.md

Large diffs are not rendered by default.

216 changes: 0 additions & 216 deletions README_CN.md

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.blinkfox</groupId>
<artifactId>stalker</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>stalker</name>
Expand Down
19 changes: 1 addition & 18 deletions src/main/java/com/blinkfox/stalker/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,9 @@ public void fail() {
*/
public void assertFaster(Options options, Runnable runnable1, Runnable runnable2) {
MeasureRunnerContext runnerContext = new MeasureRunnerContext(options);
if (calcSum(runnerContext.run(runnable1).getEachMeasures())
>= calcSum(runnerContext.run(runnable2).getEachMeasures())) {
if (runnerContext.run(runnable1).getSum() >= runnerContext.run(runnable2).getSum()) {
fail();
}
}

/**
* 计算long数组中的总和.
*
* @param arr long数组
* @return 总和
*/
private long calcSum(long[] arr) {
int sum = 0;
if (arr != null && arr.length > 0) {
for (long n : arr) {
sum += n;
}
}
return sum;
}

}
48 changes: 41 additions & 7 deletions src/main/java/com/blinkfox/stalker/Stalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.blinkfox.stalker.config.Options;
import com.blinkfox.stalker.output.MeasureOutputContext;
import com.blinkfox.stalker.result.MeasurementCollector;
import com.blinkfox.stalker.result.bean.Measurement;
import com.blinkfox.stalker.result.MeasureResult;
import com.blinkfox.stalker.result.StalkerFuture;
import com.blinkfox.stalker.runner.MeasureRunnerContext;
import java.util.List;
import lombok.experimental.UtilityClass;
Expand All @@ -17,6 +17,40 @@
@UtilityClass
public class Stalker {

/**
* 使用默认选项参数来提交可运行的异步测量任务,并立即返回此次异步任务的 {@link StalkerFuture} 实例.
*
* @param task 任务
* @return {@link StalkerFuture} 对象实例
* @author blinkfox on 2020-06-03
* @since v1.2.0
*/
public StalkerFuture submit(Runnable task) {
return submit(Options.of(), task);
}

/**
* 提交可运行的异步测量任务,并立即返回此次异步任务的 {@link StalkerFuture} 实例.
*
* <p>异步提交任务时,将默认额外开启定时更新统计数据的定时任务.</p>
*
* @param options 选项参数
* @param task 任务
* @return {@link StalkerFuture} 对象实例
* @author blinkfox on 2020-06-03
* @since v1.2.0
*/
public StalkerFuture submit(Options options, Runnable task) {
if (options == null || task == null) {
throw new IllegalArgumentException("options or runnables is null (or empty)!");
}
options.valid();

// 异步提交任务时,将默认额外开启定时更新统计数据的定时任务.
options.enableScheduledUpdater();
return MeasureRunnerContext.submit(options, task);
}

/**
* 测量要执行的代码的性能评估.
*
Expand All @@ -42,21 +76,21 @@ public List<Object> run(Options options, Runnable... runnables) {
* 测量要执行的各个代码的性能并输出统计数据的结果数组.
*
* @param options 参数选项
* @param runnables runnable
* @param runnables 可运行的任务
* @return 各个运行结果统计数据的数组
* @author blinkfox on 2020-05-14
* @since v1.1.0
*/
public Measurement[] runStatis(Options options, Runnable... runnables) {
public MeasureResult[] runStatis(Options options, Runnable... runnables) {
int len;
if (options == null || runnables == null || (len = runnables.length) == 0) {
throw new IllegalArgumentException("options or runnables is null (or empty)!");
throw new IllegalArgumentException("【Stalker 参数异常】options or runnables is null (or empty)!");
}

// 循环遍历测量各个 Runnable 实例的性能结果,然后将各个结果存放到数组中,最后统一输出出来.
Measurement[] measurements = new Measurement[len];
MeasureResult[] measurements = new MeasureResult[len];
for (int i = 0; i < len; i++) {
measurements[i] = new MeasurementCollector().collect(new MeasureRunnerContext(options).run(runnables[i]));
measurements[i] = new MeasureRunnerContext(options).run(runnables[i]);
}
return measurements;
}
Expand Down
Loading

0 comments on commit bf9757e

Please sign in to comment.