news pacs, news results

This commit is contained in:
Ilya Ig. Petrov 2015-12-07 08:56:12 +05:00
parent c11a30a319
commit 92e6872be2
5 changed files with 45202 additions and 0 deletions

View File

@ -75,3 +75,15 @@ blocked-hosts-switch.js: 88 bytes, 894410 ns, Missed: 77 bytes,
blocked-ips-switch.js: 37 bytes, 1348111 ns, Missed: 72 bytes, 597439 ns
blocked-ips-indexOf.js: 35 bytes, 4853437 ns, Missed: 72 bytes, 599850 ns
blocked-ips-binary.js: 31 bytes, 3542401 ns, Missed: 77 bytes, 602958 ns
======================
blocked-hosts-binary.js: 351 bytes, 3729603 ns, Missed: 211 bytes, 608708 ns
blocked-hosts-hash.js: 347 bytes, 5009832 ns, Missed: 207 bytes, 610767 ns
blocked-hosts-plain-switch.js: 33 bytes, 2979803 ns, Missed: 94 bytes, 617564 ns
blocked-hosts-reversed-binary.js: 108 bytes, 3771339 ns, Missed: 96 bytes, 600923 ns
blocked-hosts-switch.js: 88 bytes, 886985 ns, Missed: 81 bytes, 611207 ns
blocked-ips-binary.js: 33 bytes, 3518561 ns, Missed: 77 bytes, 614293 ns
blocked-ips-indexOf.js: 36 bytes, 4876239 ns, Missed: 80 bytes, 608928 ns
blocked-ips-switch-trie-index.js: 55 bytes, 831119 ns, Missed: 97 bytes, 606306 ns
blocked-ips-switch-trie.js: 43 bytes, 836457 ns, Missed: 86 bytes, 641512 ns
blocked-ips-switch.js: 31 bytes, 1401377 ns, Missed: 72 bytes, 637717 ns

View File

@ -12,7 +12,9 @@ public class Program
public static string RunTest(string hostsFile, string pacName, bool ifMissing = false) {
using(StreamReader hostsReader = new StreamReader(hostsFile))
{
string pacUri = "http://localhost:8080/"+pacName+"?"+new Random().Next();
Console.WriteLine(pacUri);
GC.Collect();
long memBefore = GC.GetTotalMemory(true);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,79 @@
'use strict';
module.exports = (hosts, ips, generator, generatePac) => {
function populateTrie(trie, doms) {
var dom = doms.pop();
if (!doms.length || doms.length === 1 && doms[0] === 'www') {
trie[''] = trie[''] || [];
trie[''].push( dom )
return trie;
}
if (trie[''] && trie[''].indexOf(dom) !== -1) // Subdomain of a blocked domain.
return trie;
trie[dom] = trie[dom] || {};
populateTrie( trie[dom], doms );
return trie;
}
var trie = {};
for(var ip of ips) {
var doms = ip.split('.').reverse();
populateTrie(trie, doms);
}
function trieToSwitch(trie, indent) {
var _indent = indent || '';
var indent = _indent + ' ';
var keys = Object.keys(trie).sort();
if (!trie[''] && keys.length === 1) {
var key = keys[0];
return _indent + 'if (doms.pop() === "'+key+'")\n'+ trieToSwitch(trie[key], indent);
}
var cases = '';
if (trie['']) {
var values = trie[''].sort();
if (values.length === 1 && keys.length === 1)
return _indent + 'return doms.pop() === "'+values[0]+'";\n';
cases =
values.filter( v => v ).map( val => indent +'case "'+val+'":\n' ).join('') + indent +' return true;\n';
delete trie[''];
keys = Object.keys(trie).sort();
}
cases += keys.filter( k => k ).map(
key => {
var tmp = trieToSwitch( trie[key], indent+' ');
if (!/^\s*return/.test(tmp))
tmp += indent+' break;\n';
return indent +'case "'+key+'":\n' +tmp;
}
).join('');
return ''
+ _indent +'switch( doms.pop() ) {\n'
+ cases
+ _indent +'}\n';
}
function ifProxyByTrie(host) {
var doms = dnsResolve(host).split('.').reverse();
//SWITCH
return false;
}
var ifProxyByTrieStr = ifProxyByTrie.toString().replace('//SWITCH', trieToSwitch(trie, ' '));
return generatePac( ifProxyByTrieStr, 'host' );
}