Skip to content

Commit 9657422

Browse files
committed
compare bee and mybatis
1 parent 7c52c41 commit 9657422

File tree

18 files changed

+1261
-0
lines changed

18 files changed

+1261
-0
lines changed

pom.xml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.teasoft</groupId>
5+
<artifactId>orm-compare</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.8</version>
8+
<name>orm-compare</name>
9+
<properties>
10+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11+
<maven.compiler.source>1.7</maven.compiler.source>
12+
<maven.compiler.target>1.7</maven.compiler.target>
13+
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
14+
<log4j.version>2.7</log4j.version>
15+
<mybatis-spring.version>1.2.5</mybatis-spring.version>
16+
<bee.version>1.8</bee.version>
17+
<mybatis.version>3.3.0</mybatis.version>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
20+
<maven.compiler.version>3.5.1</maven.compiler.version>
21+
<perf4j.version>0.9.16</perf4j.version>
22+
<curator.version>2.6.0</curator.version>
23+
<slf4j.version>1.7.2</slf4j.version>
24+
<jackson-databind.version>2.9.6</jackson-databind.version>
25+
<log4j.version>2.7</log4j.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.teasoft</groupId>
31+
<artifactId>bee</artifactId>
32+
<version>${bee.version}</version>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.teasoft</groupId>
37+
<artifactId>honey</artifactId>
38+
<version>${bee.version}</version>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.teasoft</groupId>
43+
<artifactId>bee-ext</artifactId>
44+
<version>${bee.version}</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>com.alibaba</groupId>
49+
<artifactId>druid</artifactId>
50+
<version>1.0.18</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.mybatis</groupId>
55+
<artifactId>mybatis</artifactId>
56+
<version>${mybatis.version}</version>
57+
</dependency>
58+
59+
<!-- <dependency> -->
60+
<!-- <groupId>org.perf4j</groupId> -->
61+
<!-- <artifactId>perf4j</artifactId> -->
62+
<!-- <version>${perf4j.version}</version> -->
63+
<!-- </dependency> -->
64+
65+
66+
<!-- log4j用这个 -->
67+
<dependency>
68+
<groupId>log4j</groupId>
69+
<artifactId>log4j</artifactId>
70+
<version>1.2.17</version>
71+
<scope>provided</scope>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.apache.logging.log4j</groupId>
76+
<artifactId>log4j-slf4j-impl</artifactId>
77+
<version>${log4j.version}</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.apache.logging.log4j</groupId>
81+
<artifactId>log4j-api</artifactId>
82+
<version>${log4j.version}</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.apache.logging.log4j</groupId>
86+
<artifactId>log4j-core</artifactId>
87+
<version>${log4j.version}</version>
88+
</dependency>
89+
90+
<dependency>
91+
<groupId>mysql</groupId>
92+
<artifactId>mysql-connector-java</artifactId>
93+
<version>${mysql-connector-java.version}</version>
94+
</dependency>
95+
96+
</dependencies>
97+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.teasoft.orm.compare;
2+
3+
import java.math.BigDecimal;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
import org.teasoft.honey.distribution.GenIdFactory;
8+
import org.teasoft.orm.compare.model.Orders;
9+
10+
public class InitData {
11+
private static boolean isFirst=true;
12+
public static Orders getOneOrders(){
13+
Orders orders=new Orders();
14+
long id=GenIdFactory.get("TestORM"); //use Bee's GenId: SerialUniqueId
15+
orders.setId(id);
16+
if(isFirst) {
17+
orders.setId(12345678912L); //for select
18+
isFirst=false; //fixed bug
19+
}
20+
orders.setUserid("testid");
21+
orders.setName("ormtest");
22+
orders.setTotal(new BigDecimal("99.96"));
23+
orders.setRemark("test");
24+
25+
// id gen from PearFlowerId as order id.
26+
long seqNo=GenIdFactory.get("","PearFlowerId");
27+
orders.setSequence(seqNo+"");
28+
29+
return orders;
30+
}
31+
32+
33+
public static List<Orders> getOrdersList(int size){
34+
List<Orders> list =new ArrayList<>();
35+
for (int i = 0; i < size; i++) {
36+
list.add(getOneOrders());
37+
}
38+
return list;
39+
}
40+
41+
public static Orders[] getOrdersArray(int size){
42+
List<Orders> list=getOrdersList(size);
43+
Orders array[]=new Orders[list.size()];
44+
for (int i = 0; i < array.length; i++) {
45+
array[i]=list.get(i);
46+
}
47+
48+
return array;
49+
}
50+
51+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2016-2020 the original author.All rights reserved.
3+
* Kingstar(honeysoft@126.com)
4+
* The license,see the LICENSE file.
5+
*/
6+
7+
package org.teasoft.orm.compare;
8+
9+
import org.teasoft.orm.compare.bee.service.BeeOrdersService;
10+
import org.teasoft.orm.compare.service.OrdersService;
11+
12+
/**
13+
* @author Kingstar
14+
* @since 1.8
15+
*/
16+
public class TestBee {
17+
18+
public static void main(String[] args) {
19+
20+
OrdersService service = new BeeOrdersService();
21+
String ormName = "Bee";
22+
23+
TestORM.test(service, ormName);
24+
// TestORM_Large.test(service, ormName);
25+
26+
}
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2016-2020 the original author.All rights reserved.
3+
* Kingstar(honeysoft@126.com)
4+
* The license,see the LICENSE file.
5+
*/
6+
7+
package org.teasoft.orm.compare;
8+
9+
import org.teasoft.orm.compare.mybatis.service.MybatisOrdersService;
10+
import org.teasoft.orm.compare.service.OrdersService;
11+
12+
/**
13+
* @author Kingstar
14+
* @since 1.8
15+
*/
16+
public class TestMybatis {
17+
18+
public static void main(String[] args) {
19+
OrdersService service=new MybatisOrdersService();
20+
String ormName="Mybatis";
21+
22+
TestORM.test(service, ormName);
23+
// TestORM_Large.test(service, ormName);
24+
}
25+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2016-2020 the original author.All rights reserved.
3+
* Kingstar(honeysoft@126.com)
4+
* The license,see the LICENSE file.
5+
*/
6+
7+
package org.teasoft.orm.compare;
8+
9+
import java.util.List;
10+
11+
import org.teasoft.orm.compare.bee.service.BeeOrdersService;
12+
import org.teasoft.orm.compare.model.Orders;
13+
import org.teasoft.orm.compare.service.OrdersService;
14+
15+
/**
16+
* @author Kingstar
17+
* @since 1.8
18+
*/
19+
public class TestORM {
20+
21+
public static void test(OrdersService service,String ormName) {
22+
23+
System.out.println("Now test the ORM: "+ormName);
24+
25+
int insertBatchSize;
26+
int selectUpdateSize;
27+
for (int i = 1; i <= 4; i++) {
28+
if(i==1){
29+
insertBatchSize=5000;
30+
selectUpdateSize=20;
31+
}else if(i==2){
32+
insertBatchSize=10000;
33+
selectUpdateSize=50;
34+
}else if(i==3){
35+
insertBatchSize=20000;
36+
selectUpdateSize=100;
37+
}else if(i==4){
38+
insertBatchSize=50000;
39+
selectUpdateSize=200;
40+
}
41+
else{ //i=5
42+
insertBatchSize=100000; //10w
43+
selectUpdateSize=500;
44+
}
45+
System.out.println("Now it is "+ i + " time.");
46+
doTest(ormName, service, insertBatchSize, selectUpdateSize);
47+
}
48+
49+
}
50+
51+
52+
private static void doTest(String ormName,OrdersService service,int insertBatchSize,int selectUpdateSize){
53+
54+
service.setCreateSize(insertBatchSize);
55+
56+
service.insertOne(); //can start the ds.
57+
58+
//test 1
59+
long start=System.currentTimeMillis();
60+
service.insertBatch(); //will use insertBatchSize
61+
long end=System.currentTimeMillis();
62+
63+
System.out.print("----test batch insert: ");
64+
System.out.println((end-start)+ " ms");
65+
66+
//test 2
67+
long start2=System.currentTimeMillis();
68+
for (int i = 0; i < selectUpdateSize; i++) {//22001
69+
List<Orders> list=service.getOrdersList(30000, 100);
70+
}
71+
long end2=System.currentTimeMillis();
72+
73+
System.out.println("----test select "+selectUpdateSize+" times: "+(end2-start2)+ " ms");
74+
75+
//test 3
76+
long start3=System.currentTimeMillis();
77+
for (int i = 0; i < selectUpdateSize; i++) {
78+
service.updateTotalByIdAndGet(100, 12345678912L); //can change the select id.
79+
// service.updateTotalByIdAndGet(100, 487024993763334L); //can change the select id.
80+
}
81+
long end3=System.currentTimeMillis();
82+
System.out.println("----test update and select "+selectUpdateSize+" times: "+(end3-start3)+ " ms");
83+
84+
System.out.println((end-start)+" "+(end2-start2)+ " "+(end3-start3));
85+
System.out.println();
86+
87+
//not for test this time.
88+
BeeOrdersService beeservice=new BeeOrdersService();
89+
beeservice.deleteOrdersById(12345678912L);
90+
}
91+
92+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2016-2020 the original author.All rights reserved.
3+
* Kingstar(honeysoft@126.com)
4+
* The license,see the LICENSE file.
5+
*/
6+
7+
package org.teasoft.orm.compare;
8+
9+
import java.util.List;
10+
11+
import org.teasoft.orm.compare.bee.service.BeeOrdersService;
12+
import org.teasoft.orm.compare.model.Orders;
13+
import org.teasoft.orm.compare.service.OrdersService;
14+
15+
/**
16+
* @author Kingstar
17+
* @since 1.8
18+
*/
19+
public class TestORM_Large {
20+
21+
public static void test(OrdersService service,String ormName) {
22+
23+
System.out.println("Now test the ORM: "+ormName);
24+
25+
int insertBatchSize;
26+
int selectUpdateSize;
27+
// for (int i = 1; i <= 4; i++) {
28+
for (int i = 5; i <= 5; i++) {
29+
30+
if(i==1){
31+
insertBatchSize=5000;
32+
selectUpdateSize=20;
33+
}else if(i==2){
34+
insertBatchSize=10000;
35+
selectUpdateSize=50;
36+
}else if(i==3){
37+
insertBatchSize=20000;
38+
selectUpdateSize=100;
39+
}else if(i==4){
40+
insertBatchSize=50000;
41+
selectUpdateSize=200;
42+
}
43+
else{ //i=5
44+
insertBatchSize=100000; //10w
45+
selectUpdateSize=500;
46+
}
47+
System.out.println("Now it is "+ i + " time.");
48+
doTest(ormName, service, insertBatchSize, selectUpdateSize);
49+
}
50+
51+
}
52+
53+
54+
private static void doTest(String ormName,OrdersService service,int insertBatchSize,int selectUpdateSize){
55+
56+
service.setCreateSize(insertBatchSize);
57+
58+
service.insertOne(); //can start the ds.
59+
60+
//test 1
61+
long start=System.currentTimeMillis();
62+
// service.insertBatch(); //will use insertBatchSize
63+
long end=System.currentTimeMillis();
64+
65+
System.out.print("----test batch insert: ");
66+
System.out.println((end-start)+ " ms");
67+
68+
//test 2
69+
long start2=System.currentTimeMillis();
70+
for (int i = 0; i < selectUpdateSize; i++) {//22001
71+
List<Orders> list=service.getOrdersList(30000, 100);
72+
}
73+
long end2=System.currentTimeMillis();
74+
75+
System.out.println("----test select "+selectUpdateSize+" times: "+(end2-start2)+ " ms");
76+
77+
//test 3
78+
long start3=System.currentTimeMillis();
79+
for (int i = 0; i < selectUpdateSize; i++) {
80+
service.updateTotalByIdAndGet(100, 12345678912L); //can change the select id.
81+
// service.updateTotalByIdAndGet(100, 487024993763334L); //can change the select id.
82+
}
83+
long end3=System.currentTimeMillis();
84+
System.out.println("----test update and select "+selectUpdateSize+" times: "+(end3-start3)+ " ms");
85+
86+
System.out.println((end-start)+" "+(end2-start2)+ " "+(end3-start3));
87+
System.out.println();
88+
89+
//not for test this time.
90+
BeeOrdersService beeservice=new BeeOrdersService();
91+
beeservice.deleteOrdersById(12345678912L);
92+
}
93+
94+
}

0 commit comments

Comments
 (0)