#include <cstdio>
#include <cstdlib>​
#include <sys/timeb.h>​
#include <ctime>
#include <ctime>


struct timeb timer_msec;
ftime(&timer_msec);

tm *ts = localtime(&timer_msec.time);

int year = ts->tm_year + 1900;
int month = ts->tm_mon + 1;
int day = ts->tm_mday;
int hour = ts->tm_hour;
int min = ts->tm_min;
int sec = ts->tm_sec;
int milli = timer_msec.millitm;




/////////////////////////////
c ++

#include <sys/time.h>
#include <chrono>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>​

auto time = std::chrono::system_clock::now();
auto mill = std::chrono::duration_cast<std::chrono::milliseconds>(time.time_since_epoch());

long long currentTimeMillis = mill.count();
int msc = currentTimeMillis % 1000;
long nowTime = currentTimeMillis / 1000;

tm *ts = localtime(&nowTime);

int year = ts->tm_year + 1900;
int month = ts->tm_mon + 1;
int day = ts->tm_mday;
int hour = ts->tm_hour;
int min = ts->tm_min;
int sec = ts->tm_sec;
char temp[1024] = { '\0' };
sprintf(temp, "%04d-%02d-%02d %02d:%02d:%02d.%d   \n",  year, month, day, hour, min, sec, msc);



Posted by 선화

2015.03.17 17:15 Java

자바 문자열 합치기


아래는 자바 문자열 합치기 속도

( StringBuilder.append, StringBuffer.append, String += )

를 비교한것이다.


소스는 단순해서 생략.


1만건

StringBuilder Loop : [10,000] AppendText : "A" Builder time : 4msc

StringBuffer Loop : [10,000] AppendText : "A" Buffer time : 1msc

String Add Loop : [10,000] AppendText : "A" Add time : 116msc


10만건

StringBuilder Loop : [100,000] AppendText : "A" Builder time : 14msc

StringBuffer Loop : [100,000] AppendText : "A" Buffer time : 7msc

String Add Loop : [100,000] AppendText : "A" Add time : 3197msc


30만건

StringBuilder Loop : [300,000] AppendText : "A" Builder time : 15msc

StringBuffer Loop : [300,000] AppendText : "A" Buffer time : 16msc

String Add Loop : [300,000] AppendText : "A" Add time : 32005msc


30만건정도 append 쯤 StringBuilder 가 앞서기 시작한다.


간단히 한줄 출력하는 용도로 System.out.println("count : "+ count);

사용되는건 딱히 무리가 없어보이지만...

StringBuilder, StringBuffer (멀티쓰레드환경) 를 쓰는게 나아보임 .

Posted by 선화

// 쿠키 가져오기 

CookieManager cookieManager = CookieManager.getInstance();

String cookie = cookieManager.getCookie(SERVER_URL);

if (cookie == null || "".equals(cookie)) {

       cookie = "cookie is empty";


// url 호출시 헤더 추가 

Map<String, String> httpHeader = new HashMap<String, String>(); 

httpHeader.put("cookie-test1", "header-insert-cookie");

httpHeader.put("cookie-test2", cookie);        

webView.loadUrl(SERVER_URL, httpHeader)



// 쿠키삭제

private void removeCookie() {

/*

//1. Webview를 통한 캐시제거

mWebview.clearHistory();

mWebview.clearCache(true);

mWebview.clearView();


//2. 쿠키매니저를 통한 캐시제거

CookieSyncManager cookieSyncManager =         CookieSyncManager.createInstance(this);

CookieManager cookieManager = CookieManager.getInstance();

cookieManager.setAcceptCookie(true);

cookieManager.removeSessionCookie();

cookieSyncManager.sync();


//3. deleteDatebase를 이용한 직접제거

this.deleteDatabase("webview.db");

this.deleteDatabase("webviewCache.db");

*/

}

Posted by 선화
이전버튼 1 2 3 4 이전버튼

블로그 이미지
선화

공지사항

Yesterday0
Today0
Total37,988

달력

 « |  » 2019.5
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

최근에 달린 댓글

최근에 받은 트랙백

글 보관함