コード例 #1
0
ファイル: test_fib.cpp プロジェクト: hettoo/racesow
void Test()
{
    printf("---------------------------------------------\n");
    printf("%s\n\n", TESTNAME);
    printf("AngelScript 2.18.1 WIP         : 2.25 secs\n");
    printf("AngelScript 2.19.1 WIP         : 2.09 secs\n");
    printf("AS 2.20.0 (home)               : 2.11 secs\n");
    printf("AS 2.20.3 (home)               : 1.97 secs\n");

    printf("\nBuilding...\n");

    asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
    engine->SetEngineProperty(asEP_BUILD_WITHOUT_LINE_CUES, true);

    COutStream out;
    engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

    asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
    mod->AddScriptSection(TESTNAME, script, strlen(script), 0);
    mod->Build();

    asIScriptContext *ctx = engine->CreateContext();

    int fibI = mod->GetFunctionIdByDecl("int fibI(int)");
    int fibR = mod->GetFunctionIdByDecl("int fibR(int)");

    ctx->Prepare(fibR);
    ctx->SetArgDWord(0, 35); // 43

    printf("Executing AngelScript version...\n");

    double time = GetSystemTimer();

    int r = ctx->Execute();

    time = GetSystemTimer() - time;

    if( r != 0 )
    {
        printf("Execution didn't terminate with asEXECUTION_FINISHED\n", TESTNAME);
        if( r == asEXECUTION_EXCEPTION )
        {
            printf("Script exception\n");
            asIScriptFunction *func = engine->GetFunctionDescriptorById(ctx->GetExceptionFunction());
            printf("Func: %s\n", func->GetName());
            printf("Line: %d\n", ctx->GetExceptionLineNumber());
            printf("Desc: %s\n", ctx->GetExceptionString());
        }
    }
    else
        printf("Time = %f secs\n", time);

    // Verify the result
    int fib = ctx->GetReturnDWord();
    if( fib != 9227465 )
        printf("Didn't get the expected fibonacci value, got %d\n", fib);

    ctx->Release();
    engine->Release();
}
コード例 #2
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.15.0             : 2.513 secs\n");
	printf("AngelScript 2.15.1 WIP         : 2.513 secs\n");

	printf("\nBuilding...\n");

 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	RegisterScriptString(engine);

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script, strlen(script), 0);
	mod->Build();

	asIScriptContext *ctx = engine->CreateContext();
	int funcId_A = mod->GetFunctionIdByDecl("void TestCall2_A()");
	int funcId_B = mod->GetFunctionIdByDecl("void TestCall2_B()");

	printf("Executing AngelScript version...\n");

	double time = GetSystemTimer();
	int r;

	for( int n = 0; n < 5000000; n++ )
	{
		ctx->Prepare(funcId_A);
		r = ctx->Execute();
		if( r != 0 ) break;
		ctx->Prepare(funcId_B);
		r = ctx->Execute();
		if( r != 0 ) break;
	}

	time = GetSystemTimer() - time;

	if( r != 0 )
	{
		printf("Execution didn't terminate with asEXECUTION_FINISHED\n", TESTNAME);
		if( r == asEXECUTION_EXCEPTION )
		{
			printf("Script exception\n");
			asIScriptFunction *func = engine->GetFunctionDescriptorById(ctx->GetExceptionFunction());
			printf("Func: %s\n", func->GetName());
			printf("Line: %d\n", ctx->GetExceptionLineNumber());
			printf("Desc: %s\n", ctx->GetExceptionString());
		}
	}
	else
		printf("Time = %f secs\n", time);

	ctx->Release();
	engine->Release();
}
コード例 #3
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.15.0             : .857 secs\n");
	printf("AngelScript 2.18.0             : .594 secs\n");
	printf("AngelScript 2.18.1 WIP         : .361 secs\n");
	printf("AngelScript 2.19.1 WIP         : .302 secs\n");
	printf("AS 2.20.0 (home)               : .289 secs\n");
	printf("AS 2.20.3 (home)               : .291 secs\n");


	printf("\nBuilding...\n");

 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script, strlen(script), 0);
	engine->SetEngineProperty(asEP_BUILD_WITHOUT_LINE_CUES, true);
	mod->Build();

	asIScriptContext *ctx = engine->CreateContext();
	ctx->Prepare(mod->GetFunctionIdByDecl("void TestBasic2()"));

	printf("Executing AngelScript version...\n");

	double time = GetSystemTimer();

	int r = ctx->Execute();

	time = GetSystemTimer() - time;

	if( r != asEXECUTION_FINISHED )
	{
		printf("Execution didn't terminate with asEXECUTION_FINISHED\n", TESTNAME);
		if( r == asEXECUTION_EXCEPTION )
		{
			printf("Script exception\n");
			asIScriptFunction *func = engine->GetFunctionById(ctx->GetExceptionFunction());
			printf("Func: %s\n", func->GetName());
			printf("Line: %d\n", ctx->GetExceptionLineNumber());
			printf("Desc: %s\n", ctx->GetExceptionString());
		}
	}
	else
		printf("Time = %f secs\n", time);

	ctx->Release();
	engine->Release();
}
コード例 #4
0
ファイル: test_call2.cpp プロジェクト: FrankStain/angelscript
void Test(double *testTime)
{
 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script, strlen(script), 0);
	mod->Build();

#ifndef _DEBUG
	asIScriptContext *ctx = engine->CreateContext();
	asIScriptFunction *func_A = mod->GetFunctionByDecl("void TestCall2_A()");
	asIScriptFunction *func_B = mod->GetFunctionByDecl("void TestCall2_B()");

	double time = GetSystemTimer();
	int r;

	for( int n = 0; n < 5000000; n++ )
	{
		ctx->Prepare(func_A);
		r = ctx->Execute();
		if( r != 0 ) break;
		ctx->Prepare(func_B);
		r = ctx->Execute();
		if( r != 0 ) break;
	}

	time = GetSystemTimer() - time;

	if( r != 0 )
	{
		printf("Execution didn't terminate with asEXECUTION_FINISHED\n", TESTNAME);
		if( r == asEXECUTION_EXCEPTION )
		{
			printf("Script exception\n");
			asIScriptFunction *func = ctx->GetExceptionFunction();
			printf("Func: %s\n", func->GetName());
			printf("Line: %d\n", ctx->GetExceptionLineNumber());
			printf("Desc: %s\n", ctx->GetExceptionString());
		}
	}
	else
		*testTime = time;

	ctx->Release();
#endif
	engine->Release();
}
コード例 #5
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.4.1             : 7.941 secs\n");
	printf("AngelScript 2.5.0 WIP 1       : 5.788 secs\n");
	printf("AngelScript 2.7.0 rev 36      : 5.727 secs\n");
	printf("AngelScript 2.7.0 rev 37      : 5.736 secs\n");

	printf("\nBuilding...\n");

 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	COutStream out;
	engine->SetCommonMessageStream(&out);

	RegisterScriptString(engine);

	engine->AddScriptSection(0, TESTNAME, script, strlen(script), 0);
	engine->Build(0);

	asIScriptContext *ctx = engine->CreateContext();
	ctx->Prepare(engine->GetFunctionIDByDecl(0, "void TestString()"));

	printf("Executing AngelScript version...\n");

	double time = GetSystemTimer();

	int r = ctx->Execute();

	time = GetSystemTimer() - time;

	if( r != 0 )
	{
		printf("Execution didn't terminate with asEXECUTION_FINISHED\n", TESTNAME);
		if( r == asEXECUTION_EXCEPTION )
		{
			printf("Script exception\n");
			printf("Func: %s\n", engine->GetFunctionName(ctx->GetExceptionFunction()));
			printf("Line: %d\n", ctx->GetExceptionLineNumber());
			printf("Desc: %s\n", ctx->GetExceptionString());
		}
	}
	else
		printf("Time = %f secs\n", time);

	ctx->Release();
	engine->Release();
}
コード例 #6
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.15.0             : 1.772 secs\n");
	printf("AngelScript 2.15.1 WIP         : 1.772 secs\n");

	printf("\nBuilding...\n");

 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
	engine->RegisterGlobalFunction("float Average(float, float)", asFUNCTION(Average), asCALL_CDECL);

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script, strlen(script), 0);
	mod->Build();

	asIScriptContext *ctx = engine->CreateContext();
	ctx->Prepare(mod->GetFunctionIdByDecl("int TestBasic()"));

	printf("Executing AngelScript version...\n");

	double time = GetSystemTimer();

	int r = ctx->Execute();

	time = GetSystemTimer() - time;

	if( r != 0 )
	{
		printf("Execution didn't terminate with asEXECUTION_FINISHED\n", TESTNAME);
		if( r == asEXECUTION_EXCEPTION )
		{
			printf("Script exception\n");
			asIScriptFunction *func = engine->GetFunctionDescriptorById(ctx->GetExceptionFunction());
			printf("Func: %s\n", func->GetName());
			printf("Line: %d\n", ctx->GetExceptionLineNumber());
			printf("Desc: %s\n", ctx->GetExceptionString());
		}
	}
	else
		printf("Time = %f secs\n", time);

	ctx->Release();
	engine->Release();
}
コード例 #7
0
ファイル: cDebounceSwitch2.c プロジェクト: KHIEM2812/mySTMlib
void cDebounceBtnDebounce(cDebounceBtn *me) {
    unsigned long tempTimer = GetSystemTimer();
    int tempTimer1 = tempTimer - me->lastTime;
    if (tempTimer1 > CHECK_MSEC) {
        cDebounceBtnProcess(me);
        me->lastTime = tempTimer;
    }
}
コード例 #8
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("Machine 1\n");
	printf("AngelScript 1.10.1 WIP 1: ??.?? secs\n");
	printf("\n");
	printf("Machine 2\n");
	printf("AngelScript 1.10.1 WIP 1: 9.544 secs\n");
	printf("AngelScript 1.10.1 WIP 2: .6949 secs\n");

	printf("\nBuilding...\n");

 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	string script = scriptBegin;
	for( int n = 0; n < 4000; n++ )
		script += scriptMiddle;
	script += scriptEnd;

	double time = GetSystemTimer();

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script.c_str(), script.size(), 0);
	int r = mod->Build();

	time = GetSystemTimer() - time;

	if( r != 0 )
		printf("Build failed\n", TESTNAME);
	else
		printf("Time = %f secs\n", time);

	engine->Release();
}
コード例 #9
0
ファイル: gpioOutput.c プロジェクト: KHIEM2812/mySTMlib
void OutputPinPatternRun(PatternedOutputPinStruct *me) {
	if (me->timeToOff < 0 || me->timeToOn < 0) {
		return;
	}
	unsigned int currentTime = GetSystemTimer();
	unsigned int deltaTime = abs(currentTime - me->lastTime);
	int statePin = me->super.myGPIO->ODR & me->super.GPIOPin;
	if (statePin == 0) { //currently is off
		if (deltaTime > me->timeToOff) {
			GPIO_WriteBit(me->super.myGPIO, me->super.GPIOPin, 1);
			me->lastTime = currentTime;
		}
	} else if (statePin != 0) { //currently is on
		if (deltaTime > me->timeToOn) {
			GPIO_WriteBit(me->super.myGPIO, me->super.GPIOPin, 0);
			me->lastTime = currentTime;
		}
	}
}
コード例 #10
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.31.0: Build 1.02 secs, Save 0.0920 secs, Load 0.125 secs\n");

	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	RegisterScriptArray(engine, true);
	RegisterStdString(engine);
	engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print), asCALL_CDECL);

	////////////////////////////////////////////
	printf("\nGenerating...\n");

	const int numArrays = 2;
#ifdef _DEBUG
	const int numElements = 10;
#else
	const int numElements = 200000;
#endif

	string script;
    std::stringstream script_buffer;
    for (unsigned i = 0; i < numArrays; i++)
    {
        script_buffer << "int[] array_" << i << " = {";
        if (numElements > 0)
        {
            script_buffer << 0;
        }
        for (unsigned j = 1; j < numElements; j++)
        {
            script_buffer << ", " << j;
        }
        script_buffer << "};";
    }
    script_buffer << std::endl << "int main() { print (\"elem 999 = \" + array_0[999] + \"\\n\"); return 0; }";
    script = script_buffer.str();

	////////////////////////////////////////////
	printf("\nBuilding...\n");

	double time = GetSystemTimer();

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script.c_str(), script.size(), 0);
	int r = mod->Build();

	time = GetSystemTimer() - time;

	if( r != 0 )
		printf("Build failed\n");
	else
		printf("Time = %f secs\n", time);

	////////////////////////////////////////////
	printf("\nSaving...\n");

	time = GetSystemTimer();

	CBytecodeStream stream("");
	mod->SaveByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);
	printf("Size = %d\n", int(stream.buffer.size()));

	////////////////////////////////////////////
	printf("\nLoading...\n");

	time = GetSystemTimer();

	asIScriptModule *mod2 = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod2->LoadByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	engine->Release();
}
コード例 #11
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.30.0 WIP:   4.14 secs\n");

 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	RegisterScriptArray(engine, true);
	RegisterStdString(engine);

	////////////////////////////////////////////
	printf("\nGenerating...\n");

#ifdef _DEBUG
	const int numLines = 40;
#else
	const int numLines = 40000;
#endif

	string script;
	script.reserve(strlen(scriptBegin) + numLines*(strlen(scriptMiddle)+5) + strlen(scriptEnd));
	script += scriptBegin;
	for( int n = 0; n < numLines; n++ )
	{
		char buf[500];
		sprintf(buf, scriptMiddle, n);
		script += buf;
	}
	script += scriptEnd;

	////////////////////////////////////////////
	printf("\nBuilding...\n");

	double time = GetSystemTimer();

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script.c_str(), script.size(), 0);
	int r = mod->Build();

	time = GetSystemTimer() - time;

	if( r != 0 )
		printf("Build failed\n", TESTNAME);
	else
		printf("Time = %f secs\n", time);

	////////////////////////////////////////////
	printf("\nSaving...\n");

	time = GetSystemTimer();

	CBytecodeStream stream("");
	mod->SaveByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);
	printf("Size = %d\n", int(stream.buffer.size()));

	////////////////////////////////////////////
	printf("\nLoading...\n");

	time = GetSystemTimer();

	asIScriptModule *mod2 = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod2->LoadByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	engine->Release();
}
コード例 #12
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("Machine 1\n");
	printf("AngelScript 1.9.0             : 11.00 secs\n");
	printf("AngelScript 1.9.1             : 9.618 secs\n");
	printf("AngelScript 1.9.2             : 8.748 secs\n");
	printf("AngelScript 1.10.0 with C++ VM: 7.073 secs\n");
	printf("AngelScript 1.10.0 with ASM VM: 7.613 secs\n");
	printf("AngelScript 1.10.1 with ASM VM: 6.432 secs\n");
	printf("\n");
	printf("Machine 2\n");
	printf("AngelScript 1.9.0             : 4.806 secs\n");
	printf("AngelScript 1.9.1             : 4.300 secs\n");
	printf("AngelScript 1.9.2             : 3.686 secs\n");
	printf("AngelScript 1.10.0 with C++ VM: 2.973 secs\n");
	printf("AngelScript 1.10.0 with ASM VM: 3.329 secs\n");
	printf("AngelScript 1.10.1 with ASM VM: 2.936 secs\n");
	printf("AngelScript 2.0.0  with C++ VM: 6.182 secs\n");
	printf("AngelScript 2.0.0  with ASM VM: 5.958 secs\n");

	printf("\nBuilding...\n");

 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	RegisterStdString(engine);

	COutStream out;
	engine->AddScriptSection(0, TESTNAME, script, strlen(script), 0);
	engine->Build(0, &out);

	asIScriptContext *ctx;
	engine->CreateContext(&ctx);
	ctx->Prepare(engine->GetFunctionIDByDecl(0, "void TestString()"));

	printf("Executing AngelScript version...\n");

	double time = GetSystemTimer();

	int r = ctx->Execute();

	time = GetSystemTimer() - time;

	if( r != 0 )
	{
		printf("Execution didn't terminate with asEXECUTION_FINISHED\n", TESTNAME);
		if( r == asEXECUTION_EXCEPTION )
		{
			printf("Script exception\n");
			printf("Func: %s\n", engine->GetFunctionName(ctx->GetExceptionFunction()));
			printf("Line: %d\n", ctx->GetExceptionLineNumber());
			printf("Desc: %s\n", ctx->GetExceptionString());
		}
	}
	else
		printf("Time = %f secs\n", time);

	ctx->Release();
	engine->Release();
}
コード例 #13
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.25.1 WIP 0: 0.28 secs\n");
	printf("AngelScript 2.25.1 WIP 1: 0.28 secs (local bytecode optimizations)\n");
	printf("AngelScript 2.25.1 WIP 2: 0.27 secs (reversed order)\n");


 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	RegisterScriptArray(engine, true);
	RegisterStdString(engine);

	////////////////////////////////////////////
	printf("\nGenerating...\n");

	const int numFuncs = 2000;
	const int numCalls = 20000;

	string script;
	script.reserve(strlen(scriptBegin) + numFuncs*(strlen(scriptFuncDecl)+5) + numCalls*(strlen(scriptMiddle)+5) + strlen(scriptEnd));
	for( int a = 0; a < numFuncs; a++ )
	{
		char buf[500];
		sprintf(buf, scriptFuncDecl, a);
		script += buf;
	}
	script += scriptBegin;
	for( int n = 0; n < numCalls; n++ )
	{
		char buf[500];
		sprintf(buf, scriptMiddle, n%numFuncs);
		script += buf;
	}
	script += scriptEnd;

	////////////////////////////////////////////
	printf("\nBuilding...\n");

	double time = GetSystemTimer();

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script.c_str(), script.size(), 0);
	int r = mod->Build();

	time = GetSystemTimer() - time;

	if( r != 0 )
		printf("Build failed\n", TESTNAME);
	else
		printf("Time = %f secs\n", time);

	////////////////////////////////////////////
	printf("\nSaving...\n");

	time = GetSystemTimer();

	CBytecodeStream stream("");
	mod->SaveByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);
	printf("Size = %d\n", int(stream.buffer.size()));

	////////////////////////////////////////////
	printf("\nLoading...\n");

	time = GetSystemTimer();

	asIScriptModule *mod2 = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod2->LoadByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	engine->Release();
}
コード例 #14
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.25.1 WIP 0: 16.86 secs\n");
	printf("AngelScript 2.25.1 WIP 1:  2.95 secs (local bytecode optimizations)\n");
	printf("AngelScript 2.25.1 WIP 2:  2.98 secs (reversed order)\n");
	printf("AngelScript 2.28.1 WIP:    2.48 secs\n");
	printf("AngelScript 2.28.2 WIP:    2.50 secs\n");

	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	RegisterScriptArray(engine, true);
	RegisterStdString(engine);

//	engine->SetEngineProperty(asEP_OPTIMIZE_BYTECODE, false);

	////////////////////////////////////////////
	printf("\nGenerating...\n");

	string script;
	script += "int var; \n";
	script += "int func(int, int, int, int, int, int, int, int) { return 0; } \n";
	script += "void main() { \n";
	script += buildSwitch(numLevels);
	script += "} \n";

	int lines = 0;
	for( unsigned int n = 0; n < script.size(); n++ )
		if( script[n] == '\n' ) lines++;
	printf("Number of lines: %d\n", lines);

	////////////////////////////////////////////
	printf("\nBuilding...\n");

	double time = GetSystemTimer();

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script.c_str(), script.size(), 0);
	int r = mod->Build();

	time = GetSystemTimer() - time;

	if( r != 0 )
		printf("Build failed\n", TESTNAME);
	else
		printf("Time = %f secs\n", time);

	////////////////////////////////////////////
	printf("\nSaving...\n");

	time = GetSystemTimer();

	CBytecodeStream stream("");
	mod->SaveByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);
	printf("Size = %d\n", int(stream.buffer.size()));

	////////////////////////////////////////////
	printf("\nLoading...\n");

	time = GetSystemTimer();

	asIScriptModule *mod2 = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod2->LoadByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	engine->Release();
}
コード例 #15
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AS 2.20.3 (home)               : .00665 secs\n");
	printf("Original...\n");
	printf("Time = 0.010541 secs\n"
		   "Time = 0.024077 secs\n"
		   "Time = 0.009444 secs\n"
		   "Time = 0.022281 secs\n"
		   "Time = 0.019826 secs\n");
	printf("Current...\n");
	printf("Time = 0.004959 secs\n"
		   "Time = 0.010941 secs\n"
		   "Time = 0.004622 secs\n"
		   "Time = 0.009473 secs\n"
		   "Time = 0.009446 secs\n");

	printf("\nBuilding...\n");

 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	int r;
	r = engine->RegisterObjectType("vector2", sizeof(float)*2, asOBJ_VALUE | asOBJ_POD); assert( r >= 0 );
	r = engine->RegisterObjectProperty("vector2", "float x", 0); assert( r >= 0 );
	r = engine->RegisterObjectProperty("vector2", "float y", 4); assert( r >= 0 );

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script, strlen(script), 0);
	mod->Build();

	double time;
	asIScriptContext *ctx = engine->CreateContext();

	printf("Executing AngelScript version...\n");

	ctx->Prepare(mod->GetFunctionIdByDecl("void test1()"));
	time = GetSystemTimer();
	r = ctx->Execute();
	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	// TODO: optimize: PSF, ADDSi, PopRPtr -> LoadObjR
	ctx->Prepare(mod->GetFunctionIdByDecl("void test2()"));
	time = GetSystemTimer();
	r = ctx->Execute();
	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	ctx->Prepare(mod->GetFunctionIdByDecl("void test3()"));
	time = GetSystemTimer();
	r = ctx->Execute();
	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	// TODO: optimize: This will benefit from when value types are inlined in script classes
	ctx->Prepare(mod->GetFunctionIdByDecl("void test4()"));
	time = GetSystemTimer();
	r = ctx->Execute();
	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	// TODO: optimize: This will benefit from when value types are inlined in script classes
	ctx->Prepare(mod->GetFunctionIdByDecl("void test5()"));
	time = GetSystemTimer();
	r = ctx->Execute();
	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	if( r != 0 )
	{
		printf("Execution didn't terminate with asEXECUTION_FINISHED\n", TESTNAME);
		if( r == asEXECUTION_EXCEPTION )
		{
			printf("Script exception\n");
			asIScriptFunction *func = engine->GetFunctionById(ctx->GetExceptionFunction());
			printf("Func: %s\n", func->GetName());
			printf("Line: %d\n", ctx->GetExceptionLineNumber());
			printf("Desc: %s\n", ctx->GetExceptionString());
		}
	}

	ctx->Release();
	engine->Release();
}
コード例 #16
0
void Test()
{
	printf("---------------------------------------------\n");
	printf("%s\n\n", TESTNAME);
	printf("AngelScript 2.25.1 WIP 0: 0.34 secs\n");
	printf("AngelScript 2.25.1 WIP 1: 0.33 secs (local bytecode optimizations)\n");
	printf("AngelScript 2.25.1 WIP 2: 0.32 secs (reversed order)\n");


 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	COutStream out;
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	RegisterScriptArray(engine, true);
	RegisterStdString(engine);

	////////////////////////////////////////////
	printf("\nGenerating...\n");

	const int numSymbols = 10000;

	string script;
	script.reserve(numSymbols * 30);

    for( int i = 0; i < numSymbols; i++ )
    {
		char buf[500];
		sprintf(buf, "const int const_%d = %d;\n", i, i);
		script += buf;
    }

	////////////////////////////////////////////
	printf("\nBuilding...\n");

	double time = GetSystemTimer();

	asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod->AddScriptSection(TESTNAME, script.c_str(), script.size(), 0);
	int r = mod->Build();

	time = GetSystemTimer() - time;

	if( r != 0 )
		printf("Build failed\n", TESTNAME);
	else
		printf("Time = %f secs\n", time);

	////////////////////////////////////////////
	printf("\nSaving...\n");

	time = GetSystemTimer();

	CBytecodeStream stream("");
	mod->SaveByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);
	printf("Size = %d\n", int(stream.buffer.size()));

	////////////////////////////////////////////
	printf("\nLoading...\n");

	time = GetSystemTimer();

	asIScriptModule *mod2 = engine->GetModule(0, asGM_ALWAYS_CREATE);
	mod2->LoadByteCode(&stream);

	time = GetSystemTimer() - time;
	printf("Time = %f secs\n", time);

	engine->Release();
}