Beanutils and Cglib's Java Bean Property copy feature performance comparison __java

Source: Internet
Author: User
Before the Actionform properties of struts to the corresponding Hibernate entity class, I used the beanutils, feel that its function can also be learned a few days ago when learning cglib It also has a bean copy function, So want to compare their performance, write a simpler test case, no more than do not know, a fright, it seems cglib performance is extraordinary AH
Package com.redbeans.test;

Import java.lang.reflect.InvocationTargetException;

Import Junit.framework.TestCase;
Import Net.sf.cglib.beans.BeanCopier;

Import Org.apache.commons.beanutils.BeanUtils;

public class Beancopytest extends TestCase {


Class Bean01 {
/** identifier field *
Private long personId;

/** Persistent field *
Private String username;

/** Persistent field *
private String password;

/** Nullable Persistent field *
Private String gender;

/** Nullable Persistent field *
Private String Email;

/** Nullable Persistent field *
Private String address;

/** Nullable Persistent field *
Private String postcode;

Public String getaddress () {
return address;
}

public void setaddress (String address) {
this.address = address;
}

Public String Getemail () {
return email;
}

public void Setemail (String email) {
This.email = email;
}

Public String Getgender () {
return gender;
}

public void Setgender (String gender) {
This.gender = gender;
}

Public String GetPassword () {
return password;
}

public void SetPassword (String password) {
This.password = password;
}

Public long Getpersonid () {
return personId;
}

public void Setpersonid (long personId) {
This.personid = personId;
}

Public String Getpostcode () {
return postcode;
}

public void Setpostcode (String postcode) {
This.postcode = postcode;
}

Public String GetUserName () {
return username;
}

public void Setusername (String username) {
This.username = Username;
}

}

Class Bean02 {
/** identifier field *
Private long personId;

/** Persistent field *
Private String username;

/** Persistent field *
private String password;

/** Nullable Persistent field *
Private String realname;

/** Nullable Persistent field *
Private String gender;

/** Nullable Persistent field *
private double height;

/** Nullable Persistent field *
private double weight;

/** Nullable Persistent field *
private int status;

/** Nullable Persistent field *
Private String telephone;

/** Nullable Persistent field *
Private String Email;

/** Nullable Persistent field *
Private String address;

/** Nullable Persistent field *
Private String postcode;

Public String getaddress () {
return address;
}

public void setaddress (String address) {
this.address = address;
}

Public String Getemail () {
return email;
}

public void Setemail (String email) {
This.email = email;
}

Public String Getgender () {
return gender;
}

public void Setgender (String gender) {
This.gender = gender;
}

Public double getheight () {
return height;
}

public void SetHeight (double height) {
This.height = height;
}

Public String GetPassword () {
return password;
}

public void SetPassword (String password) {
This.password = password;
}

Public long Getpersonid () {
return personId;
}

public void Setpersonid (long personId) {
This.personid = personId;
}

Public String Getpostcode () {
return postcode;
}

public void Setpostcode (String postcode) {
This.postcode = postcode;
}

Public String Getrealname () {
return realname;
}

public void Setrealname (String realname) {
This.realname = Realname;
}

public int GetStatus () {
return status;
}

public void setstatus (int status) {
This.status = status;
}

Public String Gettelephone () {
return telephone;
}

public void Settelephone (String telephone) {
This.telephone = telephone;
}

Public String GetUserName () {
return username;
}

public void Setusername (String username) {
This.username = Username;
}

Public double getweight () {
return weight;
}

public void Setweight (double weight) {
This.weight = weight;
}

}
public void Testcglib () {
Bean01 Bean01 = new Bean01 ();
Bean01.setaddress ("test");
Bean01.setusername ("Bean01");
Bean02 bean02 = new Bean02 ();
for (int i = 0; i < 10000; i++) {
Beancopier copier = beancopier.create (Bean01.class, Bean02.class,
FALSE);
Copier.copy (Bean01, bean02, NULL);
}
}

public void Testbeanutils () {
Bean01 Bean01 = new Bean01 ();
Bean01.setaddress ("test");
Bean01.setusername ("Bean01");
Bean02 bean02 = new Bean02 ();
for (int i = 0; i < 10000; i++) {
try {
Beanutils.copyproperties (BEAN02, Bean01);
catch (Illegalaccessexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
catch (InvocationTargetException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}

}

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.