float testFast() { Component* components[NUM_COMPONENTS]; // Create the component arrays. for (int i = 0; i < NUM_COMPONENTS; i++) { components[i] = new Component[NUM_ACTORS]; } // Run the simulation. startProfile(); int sum = 0; for (int f = 0; f < NUM_FRAMES; f++) { for (int c = 0; c < NUM_COMPONENTS; c++) { Component* componentArray = components[c]; for (int a = 0; a < NUM_ACTORS / 2; a++) { sum += componentArray[a].update(); } } } float result = endProfile("best"); if (sum != 240000000) printf("%d\n", sum); // Free everything. for (int i = 0; i < NUM_COMPONENTS; i++) { delete [] components[i]; } return result; }
/** * @fn connectToUnknownEssid */ InterfaceAnswer NetctlInterface::connectToUnknownEssid(const QString essid, QMap<QString, QString> settings) const { if (debug) qDebug() << PDEBUG; if (netctlCommand == nullptr) { if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return InterfaceAnswer::Error; } if (wpaCommand == nullptr) { if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return InterfaceAnswer::Error; } // append settings QStringList interfaces = netctlCommand->getWirelessInterfaceList(); if (interfaces.isEmpty()) return InterfaceAnswer::Error; settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); settings[QString("Interface")] = interfaces.first(); settings[QString("Connection")] = QString("wireless"); settings[QString("ESSID")] = QString("'%1'").arg(essid); settings[QString("IP")] = QString("dhcp"); // save profile QString profile = QString("netctl-gui-%1").arg(essid); profile.remove(QChar('"')).remove(QChar('\'')); if (createProfile(profile, settings) != InterfaceAnswer::True) return InterfaceAnswer::Error; // start it return startProfile(profile); }
// For each component, update each actor. The actor stores pointers to the // components, and the components are in random order. void testRandomComponents(float best) { Actor* actors = new Actor[NUM_ACTORS]; Component* components = new Component[NUM_ACTORS * NUM_COMPONENTS]; int* indexes = shuffledArray(NUM_ACTORS * NUM_COMPONENTS); // Wire up the components to the actors. for (int i = 0; i < NUM_COMPONENTS; i++) { for (int j = 0; j < NUM_ACTORS; j++) { actors[j].components[i] = &components[indexes[i * NUM_ACTORS + j]]; } } delete [] indexes; startProfile(); long sum = 0; for (int i = 0; i < NUM_COMPONENTS; i++) { for (int j = 0; j < NUM_ACTORS; j++) { sum += actors[j].components[i]->update(); } } endProfile(" random components ", best); use(sum); delete [] actors; delete [] components; }
// For each component, update each actor. The actor stores pointers to the // components, and the components are ordered in memory by component then actor. void testOrderedByComponent(float best) { Actor* actors = new Actor[NUM_ACTORS]; Component* components = new Component[NUM_ACTORS * NUM_COMPONENTS]; // Wire up the components to the actors. for (int i = 0; i < NUM_COMPONENTS; i++) { for (int j = 0; j < NUM_ACTORS; j++) { actors[j].components[i] = &components[i * NUM_ACTORS + j]; } } startProfile(); long sum = 0; for (int i = 0; i < NUM_COMPONENTS; i++) { for (int j = 0; j < NUM_ACTORS; j++) { sum += actors[j].components[i]->update(); } } endProfile("order by components ", best); use(sum); delete [] actors; delete [] components; }
/* perform the operations for a frame: * - check to see if the connections are still alive (checkAlive) * - this will emit connectionsChanged if there is a any change in the connection status * - grab a text stream of the current model data ( stream << *subjectList ) * - put the text stream on the wire s->write(...) */ void MyServer::process() { stopProfile("Other"); working = true; startProfile("checkAlive"); int alive = checkAlive(); stopProfile("checkAlive"); if(alive > 0) { startProfile("Serve"); count++; QString buffer; QTextStream stream(&buffer); // The following operation is threadsafe. startProfile("Fetch"); subjectList->read(stream, true); stopProfile("Fetch"); startProfile("Wait"); listMutex.lock(); stopProfile("Wait"); // for each connection for(QList<ServerConnection *>::iterator i = connections.begin(); i != connections.end(); i++) { QTcpSocket *s = (*i)->socket; if(s->state() != QAbstractSocket::ConnectedState) continue; QString d = QString("%1\nEND\r\n").arg(buffer); startProfile("Write"); int written = s->write(d.toUtf8()); stopProfile("Write"); if(written == -1) { emit outMessage(QString(" Error writing to %1").arg(s->peerAddress().toString())); } else { s->flush(); } } listMutex.unlock(); stopProfile("Serve"); } working = false; startProfile("Other"); }
// For each component, update each actor. The list of actors is pointers to // actors that are in random order in memory. Each actor points to components // that are in random order in memory. // // This is a realistic and also worst case. void testRandomActors(float best) { Actor* actors = new Actor[NUM_ACTORS]; Component* components = new Component[NUM_ACTORS * NUM_COMPONENTS]; int* componentIndexes = shuffledArray(NUM_ACTORS * NUM_COMPONENTS); // Wire up the components to the actors. for (int i = 0; i < NUM_COMPONENTS; i++) { for (int j = 0; j < NUM_ACTORS; j++) { actors[j].components[i] = &components[componentIndexes[i * NUM_ACTORS + j]]; } } delete [] componentIndexes; // Fill the list of actors. Actor** actorList = new Actor*[NUM_ACTORS]; int* actorIndexes = shuffledArray(NUM_ACTORS); for (int i = 0; i < NUM_ACTORS; i++) { actorList[i] = &actors[actorIndexes[i]]; } delete [] actorIndexes; startProfile(); long sum = 0; for (int i = 0; i < NUM_COMPONENTS; i++) { for (int j = 0; j < NUM_ACTORS; j++) { sum += actorList[j]->components[i]->update(); } } endProfile(" random actors ", best); use(sum); delete [] actors; delete [] components; delete [] actorList; }
/** * @fn connectToKnownEssid */ InterfaceAnswer NetctlInterface::connectToKnownEssid(const QString essid) const { if (debug) qDebug() << PDEBUG; if (netctlCommand == nullptr) { if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return InterfaceAnswer::Error; } if (wpaCommand == nullptr) { if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return InterfaceAnswer::Error; } QString profile = wpaCommand->existentProfile(essid); if (profile.isEmpty()) return InterfaceAnswer::Error; return startProfile(profile); }
// Iterate through the components in memory directly instead of going through // actors. This is the best case scenario. float testComponents() { Component* components = new Component[NUM_ACTORS * NUM_COMPONENTS]; startProfile(); long sum = 0; for (int i = 0; i < NUM_ACTORS * NUM_COMPONENTS; i++) { sum += components[i].update(); } float elapsed = endProfile(" just components "); use(sum); delete [] components; return elapsed; }
// For each actor, update all of its components. Not representative of real // game since games update all components of one type. But gives us a point of // comparison for testInline(). void testWrongOrder(float best) { InlineActor* actors = new InlineActor[NUM_ACTORS]; startProfile(); long sum = 0; for (int i = 0; i < NUM_ACTORS; i++) { for (int j = 0; j < NUM_COMPONENTS; j++) { sum += actors[i].components[j].update(); } } endProfile(" wrong order ", best); use(sum); delete [] actors; }
void testSlow(float best) { ActorBefore** actors = new ActorBefore*[NUM_ACTORS * EXTRA]; // Create a bunch of actors with random amounts of space between them. for (int i = 0; i < NUM_ACTORS * EXTRA; i++) { actors[i] = new ActorBefore(); } // Shuffle them in the list. shuffle(actors, NUM_ACTORS * EXTRA); // Deactivate half of them. for (int i = 0; i < NUM_ACTORS * EXTRA / 2; i++) { actors[i]->isActive = false; } // Shuffle them in the list. shuffle(actors, NUM_ACTORS * EXTRA); // Create a bunch of components. Component** components = new Component*[NUM_ACTORS * NUM_COMPONENTS * EXTRA]; for (int i = 0; i < NUM_ACTORS * NUM_COMPONENTS * EXTRA; i++) { components[i] = new Component(); } // Shuffle them in the list. shuffle(components, NUM_ACTORS * NUM_COMPONENTS * EXTRA); // Wire them up to actors. for (int i = 0; i < NUM_ACTORS; i++) { for (int j = 0; j < NUM_COMPONENTS; j++) { actors[i]->components[j] = components[i * NUM_COMPONENTS + j]; } } // Run the simulation. startProfile(); int sum = 0; for (int f = 0; f < NUM_FRAMES; f++) { for (int c = 0; c < NUM_COMPONENTS; c++) { for (int a = 0; a < NUM_ACTORS; a++) { if (!actors[a]->isActive) continue; sum += actors[a]->components[c]->update(); } } } endProfile("worst", best); if (sum != 240000000) printf("%d\n", sum); // Free everything. for (int i = 0; i < NUM_ACTORS; i++) { delete actors[i]; } for (int i = 0; i < NUM_ACTORS * NUM_COMPONENTS; i++) { delete components[i]; } delete [] actors; delete [] components; }