public static void test1() throws InstantiationException, IllegalAccessException {
BeanMapper beanMapper = BeanMappers.load();
Map<String, Object> source = new HashMap<String, Object>();
source.put("id", 1001l);
long begin = System.nanoTime();
BlogDetailDO obj = (BlogDetailDO) beanMapper.getFromMap("TA-BLOG-DETAIL", source);
long end = System.nanoTime();
System.out.println((end - begin) / 1000);
}
public static void test2() {
long begin = System.nanoTime();
Map<String, Object> blogCore = new HashMap<String, Object>();
Long id = ObjectUtil.toLong(blogCore.get("_id"));
Integer status = ObjectUtil.toInt(blogCore.get("status"));
Long photo_id = ObjectUtil.toLong(blogCore.get("photo_id"));
Long root_id = ObjectUtil.toLong(blogCore.get("root_id"));
Integer is_root = id.equals(root_id) ? 1 : 0;
Integer buyable = ObjectUtil.toInt(blogCore.get("buyable"));
Integer photo_width = ObjectUtil.toInt(blogCore.get("photo_width"));
Integer photo_weight = ObjectUtil.toInt(blogCore.get("photo_weight"));
String photo_path = ObjectUtil.toString(blogCore.get("photo_path"));
Long sender_id = ObjectUtil.toLong(blogCore.get("sender_id"));
String sender_username = ObjectUtil.toString(blogCore.get("sender_username"));
String sender_avatar = ObjectUtil.toString(blogCore.get("sender_avatar"));
Integer like_count = ObjectUtil.toInt(blogCore.get("like_count"));
Integer favorite_count = ObjectUtil.toInt(blogCore.get("favorite_count"));
Integer reply_count = ObjectUtil.toInt(blogCore.get("reply_count"));
String price = ObjectUtil.toString(blogCore.get("item_price"));
BlogDetailDO obj = new BlogDetailDO();
obj.setId(id);
obj.setLike_count(like_count);
obj.setStatus(status);
obj.setPhoto_id(photo_id);
obj.setRoot_id(root_id);
obj.setBuyable(buyable);
obj.setPhoto_width(photo_width);
obj.setPhoto_height(photo_weight);
obj.setPhoto_path(photo_path);
obj.setSender_id(sender_id);
obj.setSender_username(sender_username);
obj.setSender_avatar(sender_avatar);
obj.setFavorite_count(favorite_count);
obj.setReply_count(reply_count);
obj.setPrice(price);
long end = System.nanoTime();
System.out.println((end - begin) / 1000);
}
public static void test3() {
long begin = System.nanoTime();
"1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20".split(";");
long end = System.nanoTime();
System.out.println((end - begin) / 1000);
}
test1:
112
108
121
122
test2:
45
41
37
41
test3:
318
150
173
153
只要不比java string split慢就行。