Permalink
Browse files

Add in lots of changes

  • Loading branch information...
1 parent 1286d85 commit 64d504e21922c83f1fd9abfb9d9bc93df6a777ff @tageorgiou committed May 15, 2012
View
@@ -149,6 +149,10 @@ PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,
PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);
PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);
+#ifdef INSTRUMENT_DICT
+void PyDict_outputDistribution(PyObject *op);
+#endif
+
#ifdef __cplusplus
}
View
@@ -845,7 +845,7 @@ PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
* Very large dictionaries (over 50K items) use doubling instead.
* This may help applications with severe memory constraints.
*/
- if (!(mp->ma_used > n_used && mp->ma_fill*3 >= (mp->ma_mask+1)*2))
+ if (!(mp->ma_used > n_used && mp->ma_fill*4 >= (mp->ma_mask+1)*2))
return 0;
return dictresize(mp, (mp->ma_used > 50000 ? 2 : 4) * mp->ma_used);
}
@@ -2137,6 +2137,7 @@ static int
dict_traverse(PyObject *op, visitproc visit, void *arg)
{
Py_ssize_t i = 0;
+
PyObject *pk;
PyObject *pv;
@@ -3283,6 +3284,27 @@ void printInstrumentDictStats() {
fprintf(stderr, "sprobecount: %d\n", sprobecount);
fprintf(stderr, "scollisioncount: %d\n", scollisioncount);
}
+
+void PyDict_outputDistribution(PyObject *op)
+{
+ register Py_ssize_t i;
+ register Py_ssize_t mask;
+ register PyDictEntry *ep;
+ FILE* out = fopen("/tmp/dictdistr","w");
+ ep = ((PyDictObject *)op)->ma_table;
+ mask = ((PyDictObject *)op)->ma_mask;
+ i = 0;
+ while (i < mask) {
+ if (ep[i].me_value == NULL) {
+ fprintf(out, "0");
+ } else {
+ fprintf(out, "1");
+ }
+ i++;
+ }
+ fprintf(out, "\n");
+ fclose(out);
+}
#endif
#ifdef DOUBLE_HASH
View
@@ -1286,7 +1286,7 @@ string_hash(PyStringObject *a)
x = _Py_HashSecret.prefix;
#ifdef TABULATION_MAIN
while (--len >= 0) {
- register long index = (*p++) + ((len&7)<<8);
+ register long index = (*p++) + ((len&1)<<8);
//if (Py_SIZE(a) == 6)
// printf("%d, %ld\n", len, index);
x = x ^ randtable[index]; //assume we are on a 64bit machine
View
@@ -0,0 +1,21 @@
+import os
+
+versions = {
+ 'p0': '-DINSTRUMENT_DICT',
+ 'lp': '-DINSTRUMENT_DICT -DLINEAR_PROBING',
+ 'thm': '-DINSTRUMENT_DICT -DTABULATION_MAIN',
+ 'lpthm': '-DINSTRUMENT_DICT -DLINEAR_PROBING -DTABULATION_MAIN',
+}
+
+def generateVersion(version):
+ os.system('./touchall')
+ os.system('EXTRA_CFLAGS="%s" make -j2' % versions[version])
+ os.chdir('hash-table-shootout')
+ os.system('rm build/*')
+ os.system('EXTRA_CFLAGS="%s" make -j2' % versions[version])
+ os.system('cp build/python_dict benches/python_dict.%s' % version)
+ os.chdir('..')
+
+for version in versions.keys():
+ generateVersion(version)
+
Binary file not shown.
@@ -9,11 +9,12 @@
# 'qt_qhash',
'python_dict.lp',
'python_dict.lpthm',
+ 'python_dict.thm',
'python_dict.p0',
# 'ruby_hash',
]
-minkeys = 2*1000*1000
+minkeys = 1*1000*1000
#maxkeys = 40*1000*1000
maxkeys = 8*1000*1000
interval = 2*1000*1000
@@ -0,0 +1,20 @@
+from collections import defaultdict
+from matplotlib.pyplot import *
+
+lines = open('output','r').read().split()
+benches = set(map(lambda l: l.split(',')[0], lines))
+print benches
+
+def plot_bench(benchname):
+ filtered_lines = [l for l in lines if l.split(',')[0] == benchname]
+ results = defaultdict(list)
+ for line in filtered_lines:
+ benchname,size,impl_name,um,time = line.split(',')
+ results[impl_name].append(time)
+ print results
+ for key in results.keys():
+ plot(results[key], label=key)
+ legend()
+ show()
+
+plot_bench('sequentialstring')
@@ -18,4 +18,6 @@ typedef PyObject * hash_t;
#define DELETE_STR_FROM_HASH(key) do { \
PyDict_DelItemString(hash, key); \
} while(0)
+#define EXIT \
+ PyDict_outputDistribution(hash);
#include "template.c"
@@ -80,6 +80,9 @@ int main(int argc, char ** argv)
double after = get_time();
printf("%f\n", after-before);
+
+ EXIT
+
fflush(stdout);
sleep(1000000);
}
View
@@ -0,0 +1,4 @@
+#!/bin/bash
+touch Objects/unicodeobject.c
+touch Objects/dictobject.c
+touch Objects/stringobject.c

0 comments on commit 64d504e

Please sign in to comment.