From b5e63fb4463327b80a9a1b4f2e699c51349fd0db Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 6 Jun 2013 17:52:19 -0700 Subject: [PATCH] Added debug->run timing tests option to speed test some common functions (please add some more, bottom of util.cpp --- interface/src/Application.cpp | 6 +++++ interface/src/Application.h | 1 + interface/src/Avatar.cpp | 4 +-- interface/src/Util.cpp | 50 +++++++++++++++++++++++++++++++++++ interface/src/Util.h | 2 ++ 5 files changed, 61 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c85e8ecd96..c4ec512f28 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1467,6 +1467,8 @@ void Application::initMenu() { updateFrustumRenderModeAction(); QMenu* debugMenu = menuBar->addMenu("Debug"); + debugMenu->addAction("Run Timing Tests", this, SLOT(runTests())); + debugMenu->addAction("Show Render Pipeline Warnings", this, SLOT(setRenderWarnings(bool)))->setCheckable(true); debugMenu->addAction("Kill Local Voxels", this, SLOT(doKillLocalVoxels())); debugMenu->addAction("Randomize Voxel TRUE Colors", this, SLOT(doRandomizeVoxelColors()), Qt::CTRL | Qt::Key_R); @@ -1513,6 +1515,10 @@ void Application::updateFrustumRenderModeAction() { } } +void Application::runTests() { + runTimingTests(); +} + void Application::initDisplay() { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/interface/src/Application.h b/interface/src/Application.h index 15fe56c8f8..ee51ab4333 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -123,6 +123,7 @@ private slots: void cutVoxels(); void copyVoxels(); void pasteVoxels(); + void runTests(); private: static bool sendVoxelsOperation(VoxelNode* node, void* extraData); diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 76831605b4..4375f098ea 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -319,9 +319,9 @@ glm::quat Avatar::getWorldAlignedOrientation () const { void Avatar::updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight) { // Update head yaw and pitch based on mouse input - const float MOUSE_MOVE_RADIUS = 0.15f; + const float MOUSE_MOVE_RADIUS = 0.3f; const float MOUSE_ROTATE_SPEED = 4.0f; - const float MOUSE_PITCH_SPEED = 1.5f; + const float MOUSE_PITCH_SPEED = 2.0f; const int TITLE_BAR_HEIGHT = 46; float mouseLocationX = (float)mouseX / (float)screenWidth - 0.5f; float mouseLocationY = (float)mouseY / (float)screenHeight - 0.5f; diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index ac401a4e8b..9a31af93f4 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -9,6 +9,8 @@ #include "InterfaceConfig.h" #include #include +#include +#include #include #include @@ -21,6 +23,7 @@ #include "world.h" #include "Util.h" + #include "VoxelConstants.h" using namespace std; @@ -448,6 +451,53 @@ bool closeEnoughForGovernmentWork(float a, float b) { return (distance < 0.00001f); } +// Do some basic timing tests and report the results +void runTimingTests() { + // How long does it take to make a call to get the time? + const int numTests = 1000000; + int iResults[numTests]; + float fTest = 1.0; + float fResults[numTests]; + timeval startTime, endTime; + float elapsedMsecs; + gettimeofday(&startTime, NULL); + for (int i = 1; i < numTests; i++) { + gettimeofday(&endTime, NULL); + } + elapsedMsecs = diffclock(&startTime, &endTime); + printLog("gettimeofday() usecs: %f\n", 1000.0f * elapsedMsecs / (float) numTests); + + // Random number generation + gettimeofday(&startTime, NULL); + for (int i = 1; i < numTests; i++) { + iResults[i] = rand(); + } + gettimeofday(&endTime, NULL); + elapsedMsecs = diffclock(&startTime, &endTime); + printLog("rand() stored in array usecs: %f\n", 1000.0f * elapsedMsecs / (float) numTests); + + // Random number generation using randFloat() + gettimeofday(&startTime, NULL); + for (int i = 1; i < numTests; i++) { + fResults[i] = randFloat(); + } + gettimeofday(&endTime, NULL); + elapsedMsecs = diffclock(&startTime, &endTime); + printLog("randFloat() stored in array usecs: %f\n", 1000.0f * elapsedMsecs / (float) numTests); + + // PowF function + fTest = 1145323.2342f; + gettimeofday(&startTime, NULL); + for (int i = 1; i < numTests; i++) { + fTest = powf(fTest, 0.5f); + } + gettimeofday(&endTime, NULL); + elapsedMsecs = diffclock(&startTime, &endTime); + printLog("powf(f, 0.5) usecs: %f\n", 1000.0f * elapsedMsecs / (float) numTests); + +} + + diff --git a/interface/src/Util.h b/interface/src/Util.h index 05e7a21525..3e084fd16d 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -64,4 +64,6 @@ void renderOrientationDirections( glm::vec3 position, const glm::quat& orientati void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition); void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides ); +void runTimingTests(); + #endif