Query tests and questions about db4o

Source: Internet
Author: User

In the Entity Framework, we can use the take () method to retrieve only a specified amount of data, and the Entity Framework directly returns only the specified amount of data from the database.

Although db4o can also append the take () method after NQ, I have tested that it is still working to retrieve all the data first, then return the first five items from all the data ......

 

Test process

First, create two simple classes for comparison and testing:

Public class men
{
Public man (INT age)
{
This. Age = age;
}
Public int age {Get; set ;}
Public override string tostring ()
{
Return "men's age:" + age;
}
}

Public class women
{
Public women (INT age)
{
This. Age = age;
}
Public int age {Get; set ;}
Public override string tostring ()
{
Return "Female Age:" + age;
}
}

Then, in the command lineProgramIntroduce the relevant DLL of db4o, and writeCode:

Random r = new random ();
VaR DB = db4ofactory. openfile ("DB. db4o ");

For (INT I = 0; I <50000; I ++)
{
DB. Store (New Man (R. Next (100 )));
If (I <10000)
{
DB. Store (New Woman (R. Next (100 )));
}
}

Console. writeline ("Initialization is complete. Press enter to continue. ");

In this example, 50 thousand man objects and 10 thousand women objects are created and stored in the database.

Then write the test code:

Start:
Console. Readline ();

VaR A = datetime. now;
Foreach (var f in dB. query <Women> (). Take (5 ))
{
Console. writeline (f );
}
Console. writeline ("Time consumed to read female data" + datetime. Now. Subtract (a). totalmilliseconds + "millisecond ");

VaR B = datetime. now;
Foreach (var f in db. query <man> (). Take (5 ))
{
Console. writeline (f );
}
Console. writeline ("Time consumed to read man data" + datetime. Now. Subtract (B). totalmilliseconds + "millisecond ");

Console. writeline ("retest by pressing enter ");

Goto start;

Here we use the take () method to obtain the data of men and women respectively, and calculate the processing time to see if the data storage in the database has an impact on the processing time. If so, it means that db4o does not read only five data records, but reads all data.

Test result video:

It can be seen that, except for the first loading reason, reading data from women is much slower than reading data from men, all other tests are faster than reading data from women, especially in the last few tests, the time consumption ratio tends to be consistent with the proportion of data volume.

 

Is there any way for db4o to return only a specified amount of data?

After some searches, I found a lot of descriptions about db4o paging. It is necessary to retrieve a specified amount of data during the paging process, but these materials are for Java, for example, this IBM website published: open source object-oriented database db4o tour, Part 1: db4o Query Method

The paging part writes as follows:

But I really don't understand this list. get (x * 2 ). what is getlicenseplate ()? Can it be said that it only loads an IDS before it is actually used ??

I can't find any information about. net. Please kindly advise me!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.