Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
247644d9
提交
247644d9
authored
8月 20, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: tests
上级
c8a2cbb7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
179 行增加
和
10 行删除
+179
-10
TestMVStore.java
h2/src/test/org/h2/test/store/TestMVStore.java
+0
-10
TestMVStoreBenchmark.java
h2/src/test/org/h2/test/store/TestMVStoreBenchmark.java
+179
-0
没有找到文件。
h2/src/test/org/h2/test/store/TestMVStore.java
浏览文件 @
247644d9
...
...
@@ -47,8 +47,6 @@ public class TestMVStore extends TestBase {
public
void
test
()
throws
Exception
{
FileUtils
.
deleteRecursive
(
getBaseDir
(),
true
);
FileUtils
.
createDirectories
(
getBaseDir
());
testPerformanceCompareWithTreeMapHashMap
();
testMemoryUsage
();
testBackgroundExceptionListener
();
testOldVersion
();
testAtomicOperations
();
...
...
@@ -93,14 +91,6 @@ public class TestMVStore extends TestBase {
testLargerThan2G
();
}
private
void
testPerformanceCompareWithTreeMapHashMap
()
{
int
todo
;
}
private
void
testMemoryUsage
()
{
int
todo
;
}
private
void
testBackgroundExceptionListener
()
throws
Exception
{
String
fileName
=
getBaseDir
()
+
"/testBackgroundExceptionListener.h3"
;
FileUtils
.
delete
(
fileName
);
...
...
h2/src/test/org/h2/test/store/TestMVStoreBenchmark.java
0 → 100644
浏览文件 @
247644d9
/*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License, Version
* 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
store
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
org.h2.mvstore.MVStore
;
import
org.h2.test.TestBase
;
import
org.h2.util.New
;
/**
* Tests the performance and memory usage claims in the documentation.
*/
public
class
TestMVStoreBenchmark
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
test
=
TestBase
.
createCaller
().
init
();
test
.
config
.
traceTest
=
true
;
test
.
config
.
big
=
true
;
test
.
test
();
}
@Override
public
void
test
()
throws
Exception
{
if
(!
config
.
big
)
{
return
;
}
testPerformanceComparison
();
testMemoryUsageComparison
();
}
private
void
testMemoryUsageComparison
()
{
long
[]
mem
;
long
hash
,
tree
,
mv
;
String
msg
;
mem
=
getMemoryUsed
(
10000
,
10
);
hash
=
mem
[
0
];
tree
=
mem
[
1
];
mv
=
mem
[
2
];
msg
=
Arrays
.
toString
(
mem
);
assertTrue
(
msg
,
hash
<
mv
);
assertTrue
(
msg
,
tree
<
mv
);
mem
=
getMemoryUsed
(
10000
,
30
);
hash
=
mem
[
0
];
tree
=
mem
[
1
];
mv
=
mem
[
2
];
msg
=
Arrays
.
toString
(
mem
);
assertTrue
(
msg
,
mv
<
hash
);
assertTrue
(
msg
,
mv
<
tree
);
}
private
static
long
[]
getMemoryUsed
(
int
count
,
int
size
)
{
long
hash
,
tree
,
mv
;
ArrayList
<
Map
<
Integer
,
String
>>
mapList
;
long
mem
;
mapList
=
New
.
arrayList
();
mem
=
getMemory
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
mapList
.
add
(
new
HashMap
<
Integer
,
String
>(
size
));
}
addEntries
(
mapList
,
size
);
hash
=
getMemory
()
-
mem
;
mapList
.
size
();
mapList
=
New
.
arrayList
();
mem
=
getMemory
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
mapList
.
add
(
new
TreeMap
<
Integer
,
String
>());
}
addEntries
(
mapList
,
size
);
tree
=
getMemory
()
-
mem
;
mapList
.
size
();
mapList
=
New
.
arrayList
();
mem
=
getMemory
();
MVStore
store
=
MVStore
.
open
(
null
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Map
<
Integer
,
String
>
map
=
store
.
openMap
(
"t"
+
i
);
mapList
.
add
(
map
);
}
addEntries
(
mapList
,
size
);
mv
=
getMemory
()
-
mem
;
mapList
.
size
();
return
new
long
[]{
hash
,
tree
,
mv
};
}
private
static
void
addEntries
(
List
<
Map
<
Integer
,
String
>>
mapList
,
int
size
)
{
for
(
Map
<
Integer
,
String
>
map
:
mapList
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
map
.
put
(
i
,
"Hello World"
);
}
}
}
static
long
getMemory
()
{
try
{
LinkedList
<
byte
[]>
list
=
new
LinkedList
<
byte
[]>();
while
(
true
)
{
list
.
add
(
new
byte
[
1024
]);
}
}
catch
(
OutOfMemoryError
e
)
{
// ok
}
for
(
int
i
=
0
;
i
<
16
;
i
++)
{
System
.
gc
();
try
{
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
e
)
{
// ignore
}
}
return
getMemoryUsedBytes
();
}
private
void
testPerformanceComparison
()
{
if
(!
config
.
big
)
{
return
;
}
int
size
=
1000000
;
Map
<
Integer
,
String
>
map
;
map
=
new
HashMap
<
Integer
,
String
>(
size
);
long
hash
=
testPerformance
(
map
,
size
);
map
=
new
TreeMap
<
Integer
,
String
>();
long
tree
=
testPerformance
(
map
,
size
);
MVStore
store
=
MVStore
.
open
(
null
);
map
=
store
.
openMap
(
"test"
);
long
mv
=
testPerformance
(
map
,
size
);
String
msg
=
"mv "
+
mv
+
" tree "
+
tree
+
" hash "
+
hash
;
assertTrue
(
msg
,
hash
<
tree
);
assertTrue
(
msg
,
mv
<
tree
);
assertTrue
(
msg
,
hash
<
mv
);
}
private
long
testPerformance
(
Map
<
Integer
,
String
>
map
,
int
size
)
{
System
.
gc
();
long
time
=
0
;
for
(
int
t
=
0
;
t
<
3
;
t
++)
{
time
=
System
.
currentTimeMillis
();
for
(
int
b
=
0
;
b
<
3
;
b
++)
{
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
map
.
put
(
i
,
"Hello World"
);
}
for
(
int
a
=
0
;
a
<
5
;
a
++)
{
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
String
x
=
map
.
get
(
i
);
assertTrue
(
x
!=
null
);
}
}
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
map
.
remove
(
i
);
}
assertEquals
(
0
,
map
.
size
());
}
time
=
System
.
currentTimeMillis
()
-
time
;
}
// System.out.println(map.getClass().getName() + ": " + time);
return
time
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论