SlideShare a Scribd company logo
ORM各library效能分析與使用
(硬湊的主題) https://goo.gl/iLOCYN
Takuma
ORM Library
1. ormlite
2. greendao
3. realm
4. DBFlow
5. ActiveAndroid
ORM Library
1. ormlite
2. greendao
3. realm
4. DBFlow
5. ActiveAndroid
何謂ORM?
Object Relational Mapping
何謂ORM?
Object Relational Mapping
Object Role Modeling
何謂ORM?
Object Relational Mapping
Object Role Modeling
Optical Remote Module
何謂ORM?
Object Relational Mapping
Object Role Modeling
Optical Remote Module
……
何謂ORM?
Object Relational Mapping
Object Role Modeling
Optical Remote Module
……
何謂ORM?
Object Relational Mapping
Object Role Modeling
Optical Remote Module
……
總之他就是個Database概念!!!
進入正題
就算不用ORM library
也沒關係
我們還有原生的SQLite!
@Override
public void onCreate(SQLiteDatabase db) {
String DATABASE_CREATE_TABLE =
"create table newMemorandum("
+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ "date VARCHAR,"
+ "note VARCHAR,"
+ "pw VARCHAR,"
+ "reminder INT,"
+ "type VARCHAR,"
+ "memo VARCHAR"
+ ")";
db.execSQL(DATABASE_CREATE_TABLE);
}
SQLite原生寫法
我很懶!=懶是工程師的美德
我很懶=懶是工程師的美德
我很懶 == 懶是工程師的美德
@Override
public void onCreate(SQLiteDatabase sqliteDatabase, ConnectionSource connectionSource) {
try {
TableUtils.createTableIfNotExists(connectionSource, Character.class);
} catch (SQLException e) {
e.printStackTrace();
}
}
ormlite寫法
public static void main(String args[]) throws Exception {
Schema schema = new Schema(3, "com.takumalee.ormcomparison.database.greendao.dao");
createTable(schema);
generateDaoFiles(schema);
}
private static void createTable(Schema schema){
//一個Entity 對應一個 DB table
Entity point = schema.addEntity("Character");
//add table column
point.addIdProperty();
point.addStringProperty("careers").notNull();
point.addStringProperty("attributes").notNull();
}
GreenDao寫法(一)
GreenDao寫法(二)
private static void generateDaoFiles(Schema schema){
try {
DaoGenerator generator = new DaoGenerator();
//建立到指定目錄
generator.generateAll(schema, "../ORMComparison/app/src/main/java/");
} catch (Exception e){
e.printStackTrace();
}
}
……
Realm寫法
事件起源
Realm官方表示
有效能就是任性!
再跟我大聲說一次:有效能就是......
ormlite vs greenDao
GreenDao is much faster than ORMLite. It is roughly:
●3X faster at writing large numbers of objects.
●50% faster at reading in all 10000 entries in a single table.
●2X to 3X faster at an indexed read of a single row (though both were very fast).
●15X faster at doing a LIKE search for 100 records in a 10000 entry table.
WTF?
Google Play(https://goo.gl/tnirTh)
Github(https://goo.gl/RJqYu4)
Blog(http://goo.gl/IWR5Ih)
偷渡自己的記帳App:MMM
(https://goo.gl/Lg5ZdX)
ORM 效能分析實作
Insert(錯誤條件・IfNotExist)
ormlite:
- 45.9sec per 100k
greeDAO:
- 7.3sec per 100k
realm:
- 18.5sec per 100k
Insert(ormlite拿掉IfNotExist,realm拿掉Primary key)
ormlite:
- 14.1sec per 100k
greeDAO:
- 7.1sec per 100k
realm:
- 8.6sec per 100k
Query(多做了Data Access Object)
ormlite:
- 20.3sec per 100k
greeDAO:
- 11.2sec per 100k
realm:
- 287ms per 100k
Emulator Demo
Mobile Demo
ありがとう
Facebook社群

More Related Content

Similar to Orm各library效能分析與使用

SQLite and object-relational mapping in Java
SQLite and object-relational mapping in JavaSQLite and object-relational mapping in Java
SQLite and object-relational mapping in Java
Morteza Zakeri
 
Orm
OrmOrm
The tortoise and the ORM
The tortoise and the ORMThe tortoise and the ORM
The tortoise and the ORM
Frikkie van Biljon
 
Event sourcing
Event sourcingEvent sourcing
Event sourcing
Rich Lee
 
A Taste of Clojure
A Taste of ClojureA Taste of Clojure
A Taste of Clojure
David Leung
 
ORM Injection
ORM InjectionORM Injection
ORM Injection
Simone Onofri
 
Achieve the norm with Idiorm
Achieve the norm with IdiormAchieve the norm with Idiorm
Achieve the norm with Idiorm
Stipe Predanic
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity FrameworkDoncho Minkov
 
distributed system relation mapping (ORM)
distributed system relation mapping  (ORM)distributed system relation mapping  (ORM)
distributed system relation mapping (ORM)
milkesa13
 
Object-Oriented Programming in Java (Module 1)
Object-Oriented Programming in Java (Module 1)Object-Oriented Programming in Java (Module 1)
Object-Oriented Programming in Java (Module 1)
muhammadmubinmacadad2
 
Advanced DBMS- Unit 1.pdf Advanced DBMS dives into complex data management fo...
Advanced DBMS- Unit 1.pdf Advanced DBMS dives into complex data management fo...Advanced DBMS- Unit 1.pdf Advanced DBMS dives into complex data management fo...
Advanced DBMS- Unit 1.pdf Advanced DBMS dives into complex data management fo...
MandeepSingh631581
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 MinutesRyan Weaver
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented development
rajmundr
 
Introduction to Object-Relational Mapping
Introduction to Object-Relational MappingIntroduction to Object-Relational Mapping
Introduction to Object-Relational MappingAli Shakiba
 
Solr中国8月4日答疑交流v2
Solr中国8月4日答疑交流v2Solr中国8月4日答疑交流v2
Solr中国8月4日答疑交流v2longkeyy
 
XML Amsterdam - Creating structure in unstructured data
XML Amsterdam - Creating structure in unstructured dataXML Amsterdam - Creating structure in unstructured data
XML Amsterdam - Creating structure in unstructured data
Marco Gralike
 
Micro ORM vs Entity Framework
Micro ORM vs Entity FrameworkMicro ORM vs Entity Framework
Micro ORM vs Entity Framework
Axilis
 
ODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XMLODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XML
Marco Gralike
 

Similar to Orm各library效能分析與使用 (20)

SQLite and object-relational mapping in Java
SQLite and object-relational mapping in JavaSQLite and object-relational mapping in Java
SQLite and object-relational mapping in Java
 
Orm
OrmOrm
Orm
 
The tortoise and the ORM
The tortoise and the ORMThe tortoise and the ORM
The tortoise and the ORM
 
Event sourcing
Event sourcingEvent sourcing
Event sourcing
 
Entity Framework
Entity FrameworkEntity Framework
Entity Framework
 
A Taste of Clojure
A Taste of ClojureA Taste of Clojure
A Taste of Clojure
 
ORM Injection
ORM InjectionORM Injection
ORM Injection
 
Achieve the norm with Idiorm
Achieve the norm with IdiormAchieve the norm with Idiorm
Achieve the norm with Idiorm
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
distributed system relation mapping (ORM)
distributed system relation mapping  (ORM)distributed system relation mapping  (ORM)
distributed system relation mapping (ORM)
 
Object-Oriented Programming in Java (Module 1)
Object-Oriented Programming in Java (Module 1)Object-Oriented Programming in Java (Module 1)
Object-Oriented Programming in Java (Module 1)
 
Advanced DBMS- Unit 1.pdf Advanced DBMS dives into complex data management fo...
Advanced DBMS- Unit 1.pdf Advanced DBMS dives into complex data management fo...Advanced DBMS- Unit 1.pdf Advanced DBMS dives into complex data management fo...
Advanced DBMS- Unit 1.pdf Advanced DBMS dives into complex data management fo...
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 Minutes
 
Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented development
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
Introduction to Object-Relational Mapping
Introduction to Object-Relational MappingIntroduction to Object-Relational Mapping
Introduction to Object-Relational Mapping
 
Solr中国8月4日答疑交流v2
Solr中国8月4日答疑交流v2Solr中国8月4日答疑交流v2
Solr中国8月4日答疑交流v2
 
XML Amsterdam - Creating structure in unstructured data
XML Amsterdam - Creating structure in unstructured dataXML Amsterdam - Creating structure in unstructured data
XML Amsterdam - Creating structure in unstructured data
 
Micro ORM vs Entity Framework
Micro ORM vs Entity FrameworkMicro ORM vs Entity Framework
Micro ORM vs Entity Framework
 
ODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XMLODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XML
 

Orm各library效能分析與使用