您好,登錄后才能下訂單哦!
這篇文章主要講解了“JAVA中Beans與Utils哪個更好”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“JAVA中Beans與Utils哪個更好”吧!
1.apache BeanUtils 性能太差 日志太多
2.Apache PropertyUtils 性能可以參考,但是數(shù)據(jù)量大了比起Cglib 還是慢很多
3.Spring BeanUtils 上了一定的數(shù)量級別比較慢
4.Cglib BeanCopier 目前看來比較穩(wěn)定
5.com.rits.cloning ,數(shù)量級別大了 也慢
package com.helloxin.restful.api; import com.helloxin.restful.api.bo.CarBO; import com.rits.cloning.Cloner; import lombok.extern.slf4j.Slf4j; import net.sf.cglib.beans.BeanCopier; import org.apache.commons.beanutils.PropertyUtils; import org.junit.Test; import org.springframework.beans.BeanUtils; import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; @Slf4j public class BeanCopyTest { final static public Integer NUM = 10000; @Test public void beanSpringCopyTest() { List<CarBO> list = createData(NUM); long start = System.currentTimeMillis(); for(int i = 0;i< NUM;i++){ CarBO newCar = new CarBO(); BeanUtils.copyProperties(list.get(i), newCar); } log.info("duration={}", System.currentTimeMillis() - start); } @Test public void beanCglibCopyTest() { List<CarBO> list = createData(NUM); long start = System.currentTimeMillis(); BeanCopier b = BeanCopier.create(CarBO.class, CarBO.class, false); for(int i = 0;i< NUM;i++){ CarBO newCar = new CarBO(); b.copy(list.get(i), newCar, null); } log.info("duration={}", System.currentTimeMillis() - start); } @Test public void beanApacheCopyTest() throws InvocationTargetException, IllegalAccessException { List<CarBO> list = createData(NUM); long start = System.currentTimeMillis(); BeanCopier b = BeanCopier.create(CarBO.class, CarBO.class, false); for(int i = 0;i< NUM;i++){ CarBO newCar = new CarBO(); org.apache.commons.beanutils.BeanUtils.copyProperties(newCar,list.get(i)); } log.info("duration={}", System.currentTimeMillis() - start); } @Test public void beanApachePropertyUtilsCopyTest() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { List<CarBO> list = createData(NUM); long start = System.currentTimeMillis(); BeanCopier b = BeanCopier.create(CarBO.class, CarBO.class, false); for(int i = 0;i< NUM;i++){ CarBO newCar = new CarBO(); PropertyUtils.copyProperties(newCar,list.get(i)); } log.info("duration={}", System.currentTimeMillis() - start); } @Test public void beanRitsCloningTest() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { List<CarBO> list = createData(NUM); long start = System.currentTimeMillis(); Cloner cloner = new Cloner(); for(int i = 0;i< NUM;i++){ cloner.deepClone(list.get(i)); } log.info("duration={}", System.currentTimeMillis() - start); } private CarBO createData() { return CarBO.builder().make("st").numberOfSeats(12).build(); } private List<CarBO> createData(int num) { return IntStream.range(0, num).mapToObj(i -> CarBO.builder().make("st").numberOfSeats(i).build()).collect(Collectors.toList()); } }
感謝各位的閱讀,以上就是“JAVA中Beans與Utils哪個更好”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對JAVA中Beans與Utils哪個更好這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。