import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
*
*
* 模拟1一万只表 ,計算 cost times:83 ms 秒0 s
* 模拟10万只表 ,計算 cost times:397 ms 秒0 s
* 机器双核,4G内存测试
* Intel(R) 6 Series/C200 Series Chipset Family 4 port Serial ATA Storage Controller - 1C00
* @author Administrator
*
*/
public class Test {
static Random r = new Random();
static Map<String,List<Meter>> map = new HashMap<String,List<Meter>>();
static{
int temp=0,temp2 ;
int a =0;
while(a<1000){
List<Meter> aList = new ArrayList<Meter>();
for(int i=1,j=i+1;i<10;j++,i++){
Date dat = null;
Calendar cd = Calendar.getInstance();
cd.add(Calendar.DATE, i);
dat = cd.getTime();
if(i==1){
temp = i+r.nextInt(10);
}else{
temp += i+r.nextInt(10);
}
aList.add(new Meter("meter"+a,dat,temp));
}
map.put("meter"+a, aList);
a++;
}
}
//yyyy-MM-dd HH:mm:ss
static SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd");
public static void main(String[] args) {
long bg = System.currentTimeMillis();
System.out.println("开始計算。。。。");
Map<String,List<Meter>> map2 = new HashMap<String,List<Meter>>();
String tempMeterNo = null;
for(Map.Entry<String,List<Meter>> m:map.entrySet()){
System.out.print(" ");
List<Meter> cList = new ArrayList<Meter>();
for(int i=0;i<m.getValue().size();i++){
tempMeterNo = m.getKey();
Meter m1 = m.getValue().get(i);
//System.out.println(m1.getMeterNo()+"-"+dformat.format(m1.getDay())+"-"+m1.getVal());
if(i<m.getValue().size()-1){
Meter m2 = m.getValue().get(i+1);
int v = m2.getVal()-m1.getVal();
//計算差值
Meter m3 = new Meter(m1.getMeterNo(),m1.getDay(),v);
cList.add(m3);
}
}
map2.put(tempMeterNo, cList);
}
System.out.println("=======結束計算============");
long ed = System.currentTimeMillis();
System.out.println("計算 cost times:"+(ed-bg)+" ms 秒"+(ed-bg)/1000+" s");
//打印输出结果
/* long b2 = System.currentTimeMillis();
for(Map.Entry<String,List<Meter>> m:map2.entrySet()){
// System.out.print(" 結果 ");
List<Meter> cList = new ArrayList<Meter>();
for(int i=0;i<m.getValue().size();i++){
tempMeterNo = m.getKey();
Meter m1 = m.getValue().get(i);
//System.out.println(m1.getMeterNo()+"-"+dformat.format(m1.getDay())+"-"+m1.getVal());
}
}
long e2= System.currentTimeMillis();
System.out.println("打印 cost times:"+(ed-bg)+" ms");*/
}
public static Date getdate(int i)
{
Date dat = null;
Calendar cd = Calendar.getInstance();
cd.add(Calendar.DATE, i);
dat = cd.getTime();
SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp date = Timestamp.valueOf(dformat.format(dat));
return date;
}
}
class Meter {
public String meterNo;
public Date day;
public int val;
public Meter(String meterNo, Date day, int val) {
super();
this.meterNo = meterNo;
this.day = day;
this.val = val;
}
public String getMeterNo() {
return meterNo;
}
public void setMeterNo(String meterNo) {
this.meterNo = meterNo;
}
public Date getDay() {
return day;
}
public void setDay(Date day) {
this.day = day;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
}
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
*
*
* 模拟1一万只表 ,計算 cost times:83 ms 秒0 s
* 模拟10万只表 ,計算 cost times:397 ms 秒0 s
* 机器双核,4G内存测试
* Intel(R) 6 Series/C200 Series Chipset Family 4 port Serial ATA Storage Controller - 1C00
* @author Administrator
*
*/
public class Test {
static Random r = new Random();
static Map<String,List<Meter>> map = new HashMap<String,List<Meter>>();
static{
int temp=0,temp2 ;
int a =0;
while(a<1000){
List<Meter> aList = new ArrayList<Meter>();
for(int i=1,j=i+1;i<10;j++,i++){
Date dat = null;
Calendar cd = Calendar.getInstance();
cd.add(Calendar.DATE, i);
dat = cd.getTime();
if(i==1){
temp = i+r.nextInt(10);
}else{
temp += i+r.nextInt(10);
}
aList.add(new Meter("meter"+a,dat,temp));
}
map.put("meter"+a, aList);
a++;
}
}
//yyyy-MM-dd HH:mm:ss
static SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd");
public static void main(String[] args) {
long bg = System.currentTimeMillis();
System.out.println("开始計算。。。。");
Map<String,List<Meter>> map2 = new HashMap<String,List<Meter>>();
String tempMeterNo = null;
for(Map.Entry<String,List<Meter>> m:map.entrySet()){
System.out.print(" ");
List<Meter> cList = new ArrayList<Meter>();
for(int i=0;i<m.getValue().size();i++){
tempMeterNo = m.getKey();
Meter m1 = m.getValue().get(i);
//System.out.println(m1.getMeterNo()+"-"+dformat.format(m1.getDay())+"-"+m1.getVal());
if(i<m.getValue().size()-1){
Meter m2 = m.getValue().get(i+1);
int v = m2.getVal()-m1.getVal();
//計算差值
Meter m3 = new Meter(m1.getMeterNo(),m1.getDay(),v);
cList.add(m3);
}
}
map2.put(tempMeterNo, cList);
}
System.out.println("=======結束計算============");
long ed = System.currentTimeMillis();
System.out.println("計算 cost times:"+(ed-bg)+" ms 秒"+(ed-bg)/1000+" s");
//打印输出结果
/* long b2 = System.currentTimeMillis();
for(Map.Entry<String,List<Meter>> m:map2.entrySet()){
// System.out.print(" 結果 ");
List<Meter> cList = new ArrayList<Meter>();
for(int i=0;i<m.getValue().size();i++){
tempMeterNo = m.getKey();
Meter m1 = m.getValue().get(i);
//System.out.println(m1.getMeterNo()+"-"+dformat.format(m1.getDay())+"-"+m1.getVal());
}
}
long e2= System.currentTimeMillis();
System.out.println("打印 cost times:"+(ed-bg)+" ms");*/
}
public static Date getdate(int i)
{
Date dat = null;
Calendar cd = Calendar.getInstance();
cd.add(Calendar.DATE, i);
dat = cd.getTime();
SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp date = Timestamp.valueOf(dformat.format(dat));
return date;
}
}
class Meter {
public String meterNo;
public Date day;
public int val;
public Meter(String meterNo, Date day, int val) {
super();
this.meterNo = meterNo;
this.day = day;
this.val = val;
}
public String getMeterNo() {
return meterNo;
}
public void setMeterNo(String meterNo) {
this.meterNo = meterNo;
}
public Date getDay() {
return day;
}
public void setDay(Date day) {
this.day = day;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
}