#pragma once
#include "ofMain.h"
#define MAX_NUM 100000000
class ofApp : public ofBaseApp{
private:
int time1;
int time2;
int arr[MAX_NUM];
int testFunc(int i);
public:
void setup();
void draw();
void keyReleased(int key);
};
using UnityEngine;
using System.Collections;
public class IndexC : MonoBehaviour {
private int time1 = 0;
private int time2 = 0;
private const int maxNum = 100000000;
private int[] arr = new int[maxNum];
void Update () {
if (Input.GetKeyUp(KeyCode.Space)){
time1 = (int) (Time.realtimeSinceStartup*1000);
for (int i = 0; i < maxNum; i++){
arr[i] = testFunc(i);
arr[i] = arr[i] + 1;
}
time2 = (int)(Time.realtimeSinceStartup * 1000) - time1;
}
}
void OnGUI(){
if (time2 != 0){
GUI.Label(new Rect(0, 0, 100, 30), time2.ToString());
}
}
int testFunc(int i){
return i;
}
}
JavaScriptの場合
#pragma strict
private var time1:int = 0;
private var time2:int = 0;
private var maxNum:int = 100000000;
private var arr:int[] = new int[maxNum];
function Update() {
if (Input.GetKeyUp(KeyCode.Space)){
time1 = Time.realtimeSinceStartup*1000;
for (var i:int = 0; i < maxNum; i++){
arr[i] = testFunc(i);
arr[i] = arr[i] + 1;
}
time2 = Time.realtimeSinceStartup*1000 - time1;
}
}
function OnGUI() {
if (time2 != 0){
GUI.Label(new Rect(0, 0, 100, 30), time2.ToString());
}
}
function testFunc(i:int):int {
return i;
}
計算時間 (ミリ秒)
ツール
ver
言語
内容
244
Unity
4.3.5
C#
PCスタンドアローン
260
Unity
4.3.5
C#
WebPlayer htmlをFireFox v31.0で再生
497
Unity
4.3.5
JavaScript
PCスタンドアローン
531
Unity
4.3.5
JavaScript
WebPlayer htmlをFireFox v31.0で表示
1311
Unity
4.3.5
C#
Gameパネル
1468
Unity
4.3.5
JavaScript
Gameパネル
■Flash
package myproject{
import flash.display.MovieClip
import flash.events.MouseEvent;
import flash.text.TextField;
public class Index extends MovieClip {
public var maxNum:int = 100000000;
public var arr:Vector. = new Vector.(maxNum, true);
public function Index() {
stage.addEventListener(MouseEvent.CLICK,clickHandler);
}
private function clickHandler(e:MouseEvent):void
{
var time1:Number = new Date().time;
for (var i:int = 0; i < maxNum; i++) {
arr[i] = testFunc(i);
arr[i] = arr[i] + 1;
}
var time2:Number = new Date().time-time1;
var tf:TextField = new TextField();
addChild(tf);
tf.text = String(time2);
}
public function testFunc(i:int):int
{
return i;
}
}
}