http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72514

Revision: 72514
Author:   tstarling
Date:     2010-09-07 03:11:50 +0000 (Tue, 07 Sep 2010)

Log Message:
-----------
* Call ios::sync_with_stdio(false) so that it goes 100 times faster
* Use a hashtable instead of a tree for a small additional speedup
* Use timegm() instead of mktime() to avoid many stat('/etc/localtime') calls
* Return a value from main()
* Respect CFLAGS from the environment

Modified Paths:
--------------
    trunk/udplog/Makefile
    trunk/udplog/srcmisc/packet-loss.cpp

Modified: trunk/udplog/Makefile
===================================================================
--- trunk/udplog/Makefile       2010-09-07 02:51:07 UTC (rev 72513)
+++ trunk/udplog/Makefile       2010-09-07 03:11:50 UTC (rev 72514)
@@ -3,7 +3,7 @@
 LOG2UDP_OBJS = srcmisc/log2udp.o srclib/HostEntry.o srclib/IPAddress.o 
srclib/Socket.o srclib/SocketAddress.o
 UDPRECV_OBJS = srcmisc/udprecv.o srclib/IPAddress.o srclib/Socket.o 
srclib/SocketAddress.o
 UDP2LOG_OBJS = udp2log/udp2log.o udp2log/LogProcessor.o 
udp2log/Udp2LogConfig.o srclib/IPAddress.o srclib/Socket.o 
srclib/SocketAddress.o
-CFLAGS=-Wall
+CFLAGS:=$(CFLAGS) -Wall
 
 all: $(TARGETS)
 

Modified: trunk/udplog/srcmisc/packet-loss.cpp
===================================================================
--- trunk/udplog/srcmisc/packet-loss.cpp        2010-09-07 02:51:07 UTC (rev 
72513)
+++ trunk/udplog/srcmisc/packet-loss.cpp        2010-09-07 03:11:50 UTC (rev 
72514)
@@ -1,5 +1,5 @@
 #include <iostream>
-#include <map>
+#include <boost/tr1/unordered_map.hpp>
 #include <stdint.h>
 #include <boost/lexical_cast.hpp>
 #include <cstring>
@@ -9,7 +9,7 @@
 
 using std::strtok;
 
-typedef std::map<std::string, uint64_t>::iterator SeqIterator;
+typedef std::tr1::unordered_map<std::string, uint64_t>::iterator SeqIterator;
 
 struct HostData {
        HostData() : received(1), sent(0) {}
@@ -20,7 +20,7 @@
        // Number of packets sent, estimated from sequence numbers (unsampled)
        int64_t sent;
 };
-typedef std::map<std::string, HostData>::iterator HostIterator;
+typedef std::tr1::unordered_map<std::string, HostData>::iterator HostIterator;
 
 struct SampleData {
        SampleData() : total(0), outOfOrder(0), invalid(0) {}
@@ -34,7 +34,7 @@
        // Number of sampled lines which were invalid
        int64_t invalid;
 
-       std::map<std::string, HostData> hosts;
+       std::tr1::unordered_map<std::string, HostData> hosts;
 
        void Report(const struct tm * timeStruct, int sampleRate);
        void PrintRatio(int64_t numerator, int64_t denominator, double 
numeratorError);
@@ -48,7 +48,7 @@
 {
        using namespace std;
        const size_t bufSize = 65536;
-       map<string, uint64_t> seqs;
+       std::tr1::unordered_map<string, uint64_t> seqs;
        char buffer[bufSize];
        int sampleRate;
 
@@ -74,6 +74,9 @@
                exit(1);
        }
 
+       // Don't take all day due to 
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45574
+       ios::sync_with_stdio(false);
+
        while (cin.good()) {
                cin.getline(buffer, bufSize);
                if (!cin.gcount()) {
@@ -108,7 +111,7 @@
                        currentData.invalid++;
                        continue;
                }
-               currentTime = mktime(&timeStruct);
+               currentTime = timegm(&timeStruct);
 
                SeqIterator seqIter = seqs.find(strConn);
                HostIterator hostIter = currentData.hosts.find(strConn);
@@ -150,6 +153,7 @@
        // Final report
        currentTime = time(NULL);
        currentData.Report(&timeStruct, sampleRate);
+       return 0;
 }
 
 void SampleData::Report(const struct tm * timeStruct, int sampleRate) {



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to