-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The file module needs to add a few performance-related unit tests. #731…
… (#732)
- Loading branch information
Showing
4 changed files
with
103 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>run.mone</groupId> | ||
<artifactId>jcommon</artifactId> | ||
<version>1.4-jdk20-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>file</artifactId> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>run.mone</groupId> | ||
<artifactId>jcommon</artifactId> | ||
<version>1.4-jdk20-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>file</artifactId> | ||
|
||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>com.squareup.okio</groupId> | ||
<artifactId>okio</artifactId> | ||
<version>3.5.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
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
70 changes: 70 additions & 0 deletions
70
jcommon/file/src/test/java/com/xiaomi/mone/file/RandomAccessFileTest.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,70 @@ | ||
package com.xiaomi.mone.file; | ||
|
||
import com.google.common.base.Stopwatch; | ||
import okio.BufferedSource; | ||
import okio.Okio; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* @author goodjava@qq.com | ||
* @date 2023/9/21 15:25 | ||
*/ | ||
public class RandomAccessFileTest { | ||
|
||
|
||
@Test | ||
public void test1() throws IOException { | ||
AtomicInteger ai = new AtomicInteger(); | ||
MoneRandomAccessFile mra = new MoneRandomAccessFile("/tmp/data", "r", 1024 * 4); | ||
Stopwatch sw = Stopwatch.createStarted(); | ||
while (true) { | ||
String line = mra.getNextLine(); | ||
// System.out.println(line); | ||
ai.incrementAndGet(); | ||
if (null == line) { | ||
break; | ||
} | ||
} | ||
System.out.println("use time:" + sw.elapsed(TimeUnit.MILLISECONDS)); | ||
System.out.println(ai.get()); | ||
} | ||
|
||
|
||
@Test | ||
public void test2() throws IOException { | ||
RandomAccessFile mra = new RandomAccessFile("/tmp/data", "r"); | ||
Stopwatch sw = Stopwatch.createStarted(); | ||
while (true) { | ||
String line = mra.readLine(); | ||
System.out.println(line); | ||
if (null == line) { | ||
break; | ||
} | ||
} | ||
System.out.println("use time:" + sw.elapsed(TimeUnit.MILLISECONDS)); | ||
} | ||
|
||
@Test | ||
public void test3() throws IOException { | ||
AtomicInteger ai = new AtomicInteger(); | ||
BufferedSource bufferedSource = Okio.buffer(Okio.source(new File("/tmp/data"))); | ||
Stopwatch sw = Stopwatch.createStarted(); | ||
while (true) { | ||
String line = bufferedSource.readUtf8Line(); | ||
// System.out.println(line); | ||
ai.incrementAndGet(); | ||
if (null == line) { | ||
break; | ||
} | ||
} | ||
System.out.println("use time:" + sw.elapsed(TimeUnit.MILLISECONDS)); | ||
System.out.println(ai.get()); | ||
} | ||
|
||
} |