-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
1,885 additions
and
568 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
benchmark/src/main/java/com/alibaba/fastjson2/benchmark/schema/JSONSchemaBenchmark.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.alibaba.fastjson2.benchmark.schema; | ||
|
||
import com.alibaba.fastjson2.JSONObject; | ||
import com.alibaba.fastjson2.JSONSchema; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
|
||
public class JSONSchemaBenchmark { | ||
final static JSONSchema SCHEMA_UUID = JSONObject.of("type", "string", "format", "uuid").to(JSONSchema::of); | ||
final static JSONSchema SCHEMA_DATETIME = JSONObject.of("type", "string", "format", "date-time").to(JSONSchema::of); | ||
final static JSONSchema SCHEMA_DATE = JSONObject.of("type", "string", "format", "date").to(JSONSchema::of); | ||
final static JSONSchema SCHEMA_TIME = JSONObject.of("type", "string", "format", "time").to(JSONSchema::of); | ||
final static JSONSchema SCHEMA_NUMBER = JSONObject.of("type", "number", "minimum", 10).to(JSONSchema::of); | ||
|
||
@Benchmark | ||
public void format_uuid(Blackhole bh) { | ||
bh.consume( | ||
SCHEMA_UUID.isValid("a7f41390-39a9-4ca6-a13b-88cf07a41108") | ||
); | ||
} | ||
|
||
@Benchmark | ||
public void format_datetime(Blackhole bh) { | ||
bh.consume( | ||
SCHEMA_DATETIME.isValid("2017-07-21 12:13:14") | ||
); | ||
} | ||
|
||
@Benchmark | ||
public void format_date(Blackhole bh) { | ||
bh.consume( | ||
SCHEMA_DATE.isValid("2017-07-21") | ||
); | ||
} | ||
|
||
@Benchmark | ||
public void format_time(Blackhole bh) { | ||
bh.consume( | ||
SCHEMA_TIME.isValid("12:13:14") | ||
); | ||
} | ||
|
||
public static void format_perf() { | ||
long start = System.currentTimeMillis(); | ||
for (int i = 0; i < 1000 * 1000 * 10; ++i) { | ||
// SCHEMA_UUID.isValid("a7f41390-39a9-4ca6-a13b-88cf07a41108"); | ||
// SCHEMA_DATETIME.isValid("2017-07-21 12:13:14"); // 123 | ||
// SCHEMA_DATE.isValid("2017-07-21"); // 48 | ||
// SCHEMA_TIME.isValid("12:13:14"); // | ||
SCHEMA_NUMBER.isValid(9); // | ||
} | ||
long millis = System.currentTimeMillis() - start; | ||
System.out.println("millis : " + millis); | ||
// zulu17.32.13 : | ||
// zulu11.52.13 : | ||
// zulu8.58.0.13 : | ||
} | ||
|
||
public static void format_perf_test() { | ||
for (int i = 0; i < 10; i++) { | ||
format_perf(); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
format_perf_test(); | ||
// | ||
// Options options = new OptionsBuilder() | ||
// .include(JSONSchemaBenchmark.class.getName()) | ||
// .mode(Mode.Throughput) | ||
// .timeUnit(TimeUnit.MILLISECONDS) | ||
// .forks(1) | ||
// .build(); | ||
// new Runner(options).run(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.