SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
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社群

Mais conteúdo relacionado

Semelhante a Orm各library效能分析與使用

ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
Doncho Minkov
 
Doctrine2 In 10 Minutes
Doctrine2 In 10 MinutesDoctrine2 In 10 Minutes
Doctrine2 In 10 Minutes
Ryan Weaver
 
Introduction to Object-Relational Mapping
Introduction to Object-Relational MappingIntroduction to Object-Relational Mapping
Introduction to Object-Relational Mapping
Ali Shakiba
 
Solr中国8月4日答疑交流v2
Solr中国8月4日答疑交流v2Solr中国8月4日答疑交流v2
Solr中国8月4日答疑交流v2
longkeyy
 

Semelhante a 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)
 
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
 
MSR2016 - An Empirical Study on the Practice of Maintaining Object-Relational...
MSR2016 - An Empirical Study on the Practice of Maintaining Object-Relational...MSR2016 - An Empirical Study on the Practice of Maintaining Object-Relational...
MSR2016 - An Empirical Study on the Practice of Maintaining Object-Relational...
 

Último

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Cara Menggugurkan Kandungan 087776558899
 

Último (6)

Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 

Orm各library效能分析與使用