Beanutils and Cglib's Java Bean Property copy feature performance comparison __java
Last Update:2018-07-26
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 ();
}
}
}
}