-
Notifications
You must be signed in to change notification settings - Fork 478
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
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
benchmark/src/main/java/com/alibaba/fastjson2/benchmark/fastcode/DateToString.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,32 @@ | ||
package com.alibaba.fastjson2.benchmark.fastcode; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.util.Date; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class DateToString { | ||
static final Date date = new Date(1693836447048L); | ||
|
||
@Benchmark | ||
public void dateToString(Blackhole bh) throws Throwable { | ||
bh.consume(date.toString()); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options options = new OptionsBuilder() | ||
.include(DateToString.class.getName()) | ||
.mode(Mode.Throughput) | ||
.timeUnit(TimeUnit.MILLISECONDS) | ||
.warmupIterations(1) | ||
.forks(1) | ||
.build(); | ||
new Runner(options).run(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
benchmark/src/test/java/com/alibaba/fastjson2/benchmark/fastcode/DateToStringTest.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,29 @@ | ||
package com.alibaba.fastjson2.benchmark.fastcode; | ||
|
||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
public class DateToStringTest { | ||
static final Blackhole BH = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous."); | ||
static final DateToString benchmark = new DateToString(); | ||
static final int COUNT = 100_000_000; | ||
|
||
public static void dateToString() throws Throwable { | ||
for (int j = 0; j < 5; j++) { | ||
long start = System.currentTimeMillis(); | ||
for (int i = 0; i < COUNT; ++i) { | ||
benchmark.dateToString(BH); | ||
} | ||
long millis = System.currentTimeMillis() - start; | ||
System.out.println("DateToString-dateToString millis : " + millis); | ||
// zulu8.58.0.13 : | ||
// zulu11.52.13 : | ||
// zulu17.38.21 : | ||
// jdk22-ea : 2495 | ||
// jdk22-baseline : 5669 | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Throwable { | ||
dateToString(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test-jdk17/src/test/java/com/alibaba/fastjson2/fastcode/DateTest.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,15 @@ | ||
package com.alibaba.fastjson2.fastcode; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Date; | ||
|
||
public class DateTest { | ||
@Test | ||
public void test() { | ||
Date date = new Date(); | ||
String str = date.toString(); | ||
char[] chars = str.toCharArray(); | ||
System.out.println(str); | ||
} | ||
} |