[Debtags-commits] [svn] r1758 - in tagcoll/2.0: . bench tagcoll/coll
Enrico Zini
enrico at costa.debian.org
Thu May 11 02:31:43 UTC 2006
Author: enrico
Date: Thu May 11 02:31:33 2006
New Revision: 1758
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/bench/collection.cc
tagcoll/2.0/tagcoll/coll/base.h
tagcoll/2.0/tagcoll/coll/simple.cc
tagcoll/2.0/tagcoll/coll/simple.h
Log:
r2693 at viaza: enrico | 2006-05-10 15:32:52 -0500
started refactoring the benchmarks
Modified: tagcoll/2.0/bench/collection.cc
==============================================================================
--- tagcoll/2.0/bench/collection.cc (original)
+++ tagcoll/2.0/bench/collection.cc Thu May 11 02:31:33 2006
@@ -1,21 +1,21 @@
#include <bench/Benchmark.h>
-#include <tagcoll/stringf.h>
-#include <tagcoll/InputMerger.h>
#include <tagcoll/TextFormat.h>
-#include <tagcoll/BasicStringDiskIndex.h>
-#include <tagcoll/TDBIndexer.h>
-#include <tagcoll/CardinalityStore.h>
+//#include <tagcoll/BasicStringDiskIndex.h>
+#include <tagcoll/stream/sink.h>
+#include <tagcoll/coll/simple.h>
+#include <tagcoll/coll/fast.h>
+//#include <tagcoll/CardinalityStore.h>
#include <vector>
#include <iostream>
+#include <sstream>
#include <math.h>
+namespace bench_collection {
+
using namespace std;
-using namespace stringf;
using namespace tagcoll;
-namespace bench_collection {
-
/* Some utility random generator functions */
static inline int rnd(int min, int max)
@@ -38,11 +38,11 @@
// most tags.
static vector<string> items;
// Sample collection
- static InputMerger<string, string> coll;
+ static coll::Simple<string, string> coll;
// Precomputed tagsets
- static vector< OpSet<string> > tagsets;
+ static vector< std::set<string> > tagsets;
// Precomputed itemsets
- static vector< OpSet<string> > itemsets;
+ static vector< std::set<string> > itemsets;
// Compute a random number between min and max (inclusive), following a
// geometric distribution with parameter p
@@ -55,30 +55,33 @@
return res;
}
- void outputROCollection(tagcoll::Consumer<string, string>& cons);
- void benchROCollection(const tagcoll::ReadonlyCollection<string, string>& coll);
- void benchCollection(tagcoll::Collection<string, string>& coll);
+ template<typename OUT>
+ void outputROCollection(const OUT& cons);
+ template<typename COLL>
+ void benchROCollection(const COLL& coll);
+ template<typename COLL>
+ void benchCollection(COLL& coll);
- OpSet<string> makeTagset(double p)
+ std::set<string> makeTagset(double p)
{
- OpSet<string> res;
+ std::set<string> res;
size_t ntags = rndGeom(1, 20, p);
for (size_t j = 0; j < ntags; j++)
{
int idx = rndGeom(0, tags.size() - 1, 0.01);
- res += tags[idx];
+ res.insert(tags[idx]);
}
return res;
}
- OpSet<string> makeItemset(double p)
+ std::set<string> makeItemset(double p)
{
- OpSet<string> res;
+ std::set<string> res;
size_t nitems = rndGeom(1, 10, p);
for (size_t j = 0; j < nitems; j++)
{
int idx = rndGeom(0, items.size() - 1, 0.001);
- res += items[idx];
+ res.insert(items[idx]);
}
return res;
}
@@ -90,16 +93,24 @@
{
// Create the tag vocabulary
for (int i = 0; i < 500; i++)
- tags.push_back("tag" + fmt(i));
+ {
+ stringstream tag;
+ tag << "tag" << i;
+ tags.push_back(tag.str());
+ }
// Create the package set
for (int i = 0; i < 10000; i++)
- items.push_back("pkg" + fmt(i));
+ {
+ stringstream pkg;
+ pkg << "pkg" << i;
+ items.push_back(pkg.str());
+ }
// Create the test collection
for (size_t i = 0; i < items.size(); i++)
- coll.consume(
- items[i],
+ coll.insert(
+ wibble::singleton(items[i]),
makeTagset((((double)items.size() - (double)i) / (double)items.size())/2)
);
@@ -116,16 +127,18 @@
vector<string> CollectionBench::tags;
vector<string> CollectionBench::items;
-InputMerger<string, string> CollectionBench::coll;
-vector< OpSet<string> > CollectionBench::tagsets;
-vector< OpSet<string> > CollectionBench::itemsets;
+coll::Simple<string, string> CollectionBench::coll;
+vector< std::set<string> > CollectionBench::tagsets;
+vector< std::set<string> > CollectionBench::itemsets;
-void CollectionBench::outputROCollection(tagcoll::Consumer<string, string>& cons)
+template<typename OUT>
+void CollectionBench::outputROCollection(const OUT& out)
{
- coll.output(cons);
+ coll.output(out);
}
-void CollectionBench::benchROCollection(const tagcoll::ReadonlyCollection<string, string>& coll)
+template<typename COLL>
+void CollectionBench::benchROCollection(const COLL& coll)
{
{
Timer t = mktimer("hasTag");
@@ -138,7 +151,7 @@
}{
Timer t = mktimer("getTags[items]");
for (size_t i = 0; i < itemsets.size(); i++)
- coll.getTags(itemsets[i]);
+ coll.getMergedTags(itemsets[i]);
}{
Timer t = mktimer("getItems[tag]");
for (size_t i = 0; i < tags.size(); i++)
@@ -146,7 +159,7 @@
}{
Timer t = mktimer("getItems[tags]");
for (size_t i = 0; i < tagsets.size(); i++)
- coll.getItems(tagsets[i]);
+ coll.getCommonItems(tagsets[i]);
}{
Timer t = mktimer("getTaggedItems");
coll.getTaggedItems();
@@ -163,23 +176,23 @@
coll.getCompanionTags(tagsets[i]);
}
// TODO: getRelatedItems
- Sink<string, string> sink;
{
Timer t = mktimer("output");
for (size_t i = 0; i < tagsets.size(); i++)
- coll.output(sink);
+ coll.output(stream::sink());
}{
Timer t = mktimer("outputHavingTags");
for (size_t i = 0; i < tagsets.size(); i++)
- coll.outputHavingTags(tagsets[i], sink);
+ coll.outputHavingTags(tagsets[i], stream::sink());
}
}
-void CollectionBench::benchCollection(tagcoll::Collection<string, string>& coll)
+template<typename COLL>
+void CollectionBench::benchCollection(COLL& coll)
{
}
-class benchInputMerger : public CollectionBench
+class benchSimple : public CollectionBench
{
protected:
virtual void main()
@@ -187,11 +200,11 @@
Timer main = mktimer("total");
Timer t1 = mktimer("instantiating collection");
- InputMerger<string, string> coll;
+ coll::Simple<string, string> coll;
t1.done();
Timer t2 = mktimer("populating collection");
- outputROCollection(coll);
+ outputROCollection(inserter(coll));
t2.done();
{
@@ -201,9 +214,10 @@
}
public:
- benchInputMerger() : CollectionBench("InputMerger") {}
+ benchSimple() : CollectionBench("Simple") {}
};
+#if 0
class benchBasicStringDiskIndex : public CollectionBench
{
protected:
@@ -238,6 +252,7 @@
unlink("bench-basicstringdiskindex.tmp");
}
};
+#endif
#if 0
class benchTDBReadonlyDiskIndex : public CollectionBench
@@ -283,16 +298,16 @@
};
#endif
-class benchTDBIndexer : public CollectionBench
+class benchFast : public CollectionBench
{
protected:
virtual void main()
{
Timer main = mktimer("total");
- TDBIndexer<string, string> coll;
+ coll::Fast<string, string> coll;
Timer t1 = mktimer("indexing collection");
- outputROCollection(coll);
+ outputROCollection(inserter(coll));
t1.done();
{
@@ -302,10 +317,10 @@
}
public:
- benchTDBIndexer() : CollectionBench("TDBIndexer") {}
+ benchFast() : CollectionBench("Fast") {}
};
-
+#if 0
class benchCardinalityStore : public CollectionBench
{
protected:
@@ -327,17 +342,18 @@
public:
benchCardinalityStore() : CollectionBench("CardinalityStore") {}
};
+#endif
class top : public Benchmark
{
public:
top() : Benchmark("collection")
{
- addChild(new benchInputMerger());
- addChild(new benchBasicStringDiskIndex());
+ addChild(new benchSimple());
+ //addChild(new benchBasicStringDiskIndex());
//addChild(new benchTDBReadonlyDiskIndex());
- addChild(new benchTDBIndexer());
- addChild(new benchCardinalityStore());
+ addChild(new benchFast());
+ //addChild(new benchCardinalityStore());
}
};
Modified: tagcoll/2.0/tagcoll/coll/base.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/base.h (original)
+++ tagcoll/2.0/tagcoll/coll/base.h Thu May 11 02:31:33 2006
@@ -42,46 +42,6 @@
template<typename Self>
class ReadonlyCollection
{
-#if 0
- template<typename OUT>
- class Forwarder : public Consumer<ITEM, TAG>
- {
- OUT out;
-
- virtual void consumeItemUntagged(const ITEM& item)
- {
- *out = std::make_pair(wibble::Singleton<ITEM>(item), wibble::Empty<TAG>());
- ++out;
- }
-
- /// Process a tagged item, with its tags
- virtual void consumeItem(const ITEM& item, const std::set<TAG>& tags)
- {
- *out = std::make_pair(wibble::Singleton<ITEM>(item), tags);
- ++out;
- }
-
- /// Process a set of items, all with no tags
- virtual void consumeItemsUntagged(const std::set<ITEM>& items)
- {
- *out = std::make_pair(items, wibble::Empty<TAG>());
- ++out;
- }
-
- /// Process a set of items identically tagged, with their tags
- virtual void consumeItems(const std::set<ITEM>& items, const std::set<TAG>& tags)
- {
- *out = std::make_pair(items, tags);
- ++out;
- }
-
- public:
- Forwarder(const OUT& out) : out(out) {}
- virtual ~Forwarder() {}
- };
-#endif
-
-//protected:
/**
* Get the items which are tagged with at least the tag `tag'
*
@@ -279,7 +239,7 @@
* given tags
*/
template<typename TAGS, typename OUT>
- void outputHavingTags(const TAGS& tags, OUT& out) const
+ void outputHavingTags(const TAGS& tags, OUT out) const
{
typename coll_traits<Self>::itemset_type items = getItemsHavingTags(tags);
for (typename coll_traits<Self>::itemset_type::const_iterator i = items.begin();
Modified: tagcoll/2.0/tagcoll/coll/simple.cc
==============================================================================
--- tagcoll/2.0/tagcoll/coll/simple.cc (original)
+++ tagcoll/2.0/tagcoll/coll/simple.cc Thu May 11 02:31:33 2006
@@ -98,7 +98,7 @@
#endif
template<class ITEM, class TAG> template<typename TAGS, typename OUT>
-void Simple<ITEM, TAG>::outputHavingTags(const TAGS& ts, OUT& out) const
+void Simple<ITEM, TAG>::outputHavingTags(const TAGS& ts, OUT out) const
{
for (typename map< ITEM, std::set<TAG> >::const_iterator i = coll.begin();
i != coll.end(); ++i)
Modified: tagcoll/2.0/tagcoll/coll/simple.h
==============================================================================
--- tagcoll/2.0/tagcoll/coll/simple.h (original)
+++ tagcoll/2.0/tagcoll/coll/simple.h Thu May 11 02:31:33 2006
@@ -84,6 +84,8 @@
template<typename ITEMS, typename TAGS>
void insert(const ITEMS& items, const TAGS& tags)
{
+ using namespace wibble::operators;
+
if (tags.empty())
return;
for (typename ITEMS::const_iterator i = items.begin();
@@ -105,7 +107,7 @@
std::set<ITEM> getCommonItems(const TAGS& tag) const;
template<typename TAGS, typename OUT>
- void outputHavingTags(const TAGS& tags, OUT& out) const;
+ void outputHavingTags(const TAGS& tags, OUT out) const;
#if 0
void output(Consumer<ITEM, TAG>& consumer) const;
More information about the Debtags-commits
mailing list