アプリ版:「スタンプのみでお礼する」機能のリリースについて

X軸が秒単位、Y軸が何秒ごとの数を表したグラフを作る際に書いたコードなのですが、
データが増えすぎると処理時間が長くなるので、もっと処理速度の速いアルゴリズムはないでしょうか?
class JsonDate{
public $start_time;//エポックタイム
public $end_time;//エポックタイム
public $duration = 2;//単位は秒

function getDateCounts(){
$this->start_time = 1369706475;
$this->end_time = 1369706492;
/*
$dates配列の中身は昇順です
*/
$dates = array(
1369706475,
1369706477,
1369706478,
1369706479,
1369706481,
1369706486,
1369706486,
1369706487,
1369706489,
1369706492,
);
$dateCounts = array();
for($to = $this->start_time + $this->duration;$to < $this->end_time; $to+=$this->duration){
$from = $to - $this->duration;
if(!isset($dateCounts[$to]))$dateCounts[$to] = 0;
foreach ($dates as $i => $date){
if($from < $date ){
if($date <= $to){
$dateCounts[$to]++;
}else{
break;
}
}else{
unset($dates[$i]);
}
}
}
return $dateCounts;
}
}
$JD = new JsonDate();
$dateCounts = $JD->getDateCounts();
print_r($dateCounts);

結果は
(
[1369706477] => 1
[1369706479] => 2
[1369706481] => 1
[1369706483] => 0
[1369706485] => 0
[1369706487] => 3
[1369706489] => 1
[1369706491] => 0
)

A 回答 (1件)

(私の頭がカタいだけかもしれませんが)ちょっとこれだけでは何をしているのか分かりづらいですねぇ・・・



とりあえず他の回答者さんのために整形したコード貼っておきます
http://ideone.com/Qk3Ld9

この回答への補足

わざわざありがとうございます
Yahoo知恵袋はTABが反映されないんですよね・・・

補足日時:2013/05/28 18:58
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!