static public TrieFilter GetInstance() { if (s_instance == null) { s_instance = new TrieFilter(); s_instance.Init(); } return(s_instance); }
static int GetInstance(IntPtr L) { try { ToLua.CheckArgsCount(L, 0); TrieFilter o = TrieFilter.GetInstance(); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int AddKey(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); TrieFilter obj = (TrieFilter)ToLua.CheckObject(L, 1, typeof(TrieFilter)); string arg0 = ToLua.CheckString(L, 2); obj.AddKey(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int FindOne(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); TrieFilter obj = (TrieFilter)ToLua.CheckObject(L, 1, typeof(TrieFilter)); string arg0 = ToLua.CheckString(L, 2); string o = obj.FindOne(arg0); LuaDLL.lua_pushstring(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int FindAll(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); TrieFilter obj = (TrieFilter)ToLua.CheckObject(L, 1, typeof(TrieFilter)); string arg0 = ToLua.CheckString(L, 2); System.Collections.Generic.List <string> o = obj.FindAll(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int _CreateTrieFilter(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { TrieFilter obj = new TrieFilter(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: TrieFilter.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public static void Main() { int iters = 1000; int msgLength = 100; Print("-- Begin filter benchmark --"); Print("Number of messages scanned: " + iters); Print("Message length: " + msgLength); string [] words = { "wtf", "wop", "w***e", "whoar", "wetback", "wank", "v****a", "twaty", "twat", "titty", "titties", "t**s", "testicles", "teets", "spunk", "spic", "snatch", "smut", "s***s", "s**t", "sleaze", "slag", "shiz", "shitty", "s*******s", "s******g", "shitters", "shitter", "s*****d", "shits", "shitings", "shiting", "shitfull", "shited", "shit", "shemale", "sheister", "sh!t", "scrotum", "screw", "schlong", "retard", "qweef", "queer", "queef", "pussys", "pussy", "pussies", "p***e", "punk", "prostitute", "pricks", "prick", "pr0n", "pornos", "pornography", "porno", "p**n", "pissoff", "pissing", "pissin", "pisses", "pissers", "pisser", "pissed", "piss", "pimp", "phuq", "phuks", "phukking", "phukked", "phuking", "phuked", "phuk", "phuck", "phonesex", "penis", "pecker", "o*****s", "o****m", "orgasims", "orgasim", "niggers", "nigger", "n***a", "nerd", "muff", "mound", "motherfucks", "motherfuckings", "motherfucking", "motherfuckin", "motherfuckers", "m**********r", "motherfucked", "motherfuck", "mothafucks", "mothafuckings", "mothafucking", "mothafuckin", "mothafuckers", "mothafucker", "mothafucked", "mothafuckaz", "mothafuckas", "m********a", "mothafuck", "mick", "merde", "m********e", "lusting", "lust", "loser", "lesbo", "lesbian", "kunilingus", "kums", "kumming", "kummer", "kum", "kuksuger", "kuk", "kraut", "kondums", "kondum", "kock", "knob", "kike", "kawk", "j**z", "jizm", "j*z", "jism", "jesus h christ", "jesus f*****g christ", "jerk-off", "jerk", "jap", "jackoff", "jacking off", "jackass", "jack-off", "jack off", "hussy", "hotsex", "horny", "horniest", "hore", "hooker", "honkey", "h**o", "hoer", "hell", "hardcoresex", "hard on", "h4x0r", "h0r", "guinne", "gook", "gonads", "goddamn", "gazongers", "gaysex", "gay", "gangbangs", "gangbanged", "g******g", "fux0r", "furburger", "fuks", "fuk", "f***s", "f****e", "f******s", "f*****g", "f****n", "fuckers", "f****r", "f****d", "f**k", "fu", "foreskin", "fistfucks", "fistfuckings", "fistfucking", "fistfuckers", "fistfucker", "fistfucked", "fistfuck", "fingerfucks", "fingerfucking", "fingerfuckers", "fingerfucker", "fingerfucked", "fingerfuck", "f******o", "felatio", "feg", "feces", "fcuk", "fatso", "fatass", "farty", "farts", "fartings", "farting", "farted", "fart", "fags", "fagots", "fagot", "faggs", "f****t", "faggit", "fagging", "fagget", "f*g", "e*********n", "ejaculatings", "ejaculating", "ejaculates", "ejaculated", "e*******e", "dyke", "dumbass", "douche bag", "dong", "dipshit", "dinks", "dink", "dildos", "d***o", "dike", "dick", "damn", "damn", "cyberfucking", "cyberfuckers", "cyberfucker", "cyberfucked", "cyberfuck", "cyberfuc", "cunts", "cuntlicking", "cuntlicker", "cuntlick", "c**t", "cunnilingus", "cunillingus", "cunilingus", "cumshot", "cums", "cumming", "cummer", "cum", "crap", "cooter", "cocksucks", "cocksucking", "c********r", "cocksucked", "cocksuck", "cocks", "c**k", "cobia", "clits", "c**t", "clam", "circle jerk", "chink", "cawk", "buttpicker", "butthole", "butthead", "buttfucker", "buttfuck", "buttface", "butt hair", "butt f****r", "butt breath", "butt", "butch", "bung hole", "bum", "bullshit", "bull shit", "bucket c**t", "browntown", "browneye", "brown eye", "boner", "bonehead", "blowjobs", "b*****b", "blow job", "bitching", "bitchin", "bitches", "bitchers", "bitcher", "bitch", "bestiality", "bestial", "belly whacker", "beaver", "beastility", "beastiality", "beastial", "bastard", "balls", "asswipe", "asskisser", "assholes", "asshole", "asses", "ass lick", "ass" }; List <string> wordList = new List <string> (words); TrieFilter myTrie = new TrieFilter(wordList); Regex wordsRegex = new Regex(String.Join("|", wordList.ToArray()), RegexOptions.Compiled); string testMsg = ""; string filterResult = ""; while (testMsg.Length < msgLength) { //Worst case, whole message is bad //testMsg += wordList[rand.Next(wordList.Count)]; //Random 16-bit characters //testMsg += (char)rand.Next(1<<16); testMsg += (char)(rand.Next(26) + 97); if (rand.Next(100) < 5) { testMsg += wordList[rand.Next(wordList.Count)]; } } Print("Test message:"); Print(testMsg); // ----- Run the tests! ----- Print("\n-- START TRIE TEST --"); Print("Filtering " + iters + " messages..."); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < iters; i++) { filterResult = myTrie.replaceAllWords(testMsg); } Print("Filtered message sample:\n" + filterResult); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Print("Time: " + elapsedTime); Print("Messages/sec: " + (iters / ts.TotalSeconds)); // ----- Print("\n-- START OPTIMIZED REGEX TEST --"); Print("Filtering " + iters + " messages..."); stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < iters; i++) { filterResult = wordsRegex.Replace(testMsg, "****"); } Print("Filtered message sample:\n" + filterResult); stopWatch.Stop(); ts = stopWatch.Elapsed; elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Print("Time: " + elapsedTime); Print("Messages/sec: " + (iters / ts.TotalSeconds)); // ----- Print("\n-- START PER-WORD REGEX TEST --"); Print("Filtering " + iters + " messages..."); stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < iters; i++) { filterResult = testMsg; foreach (string naughtyWord in wordList) { filterResult = Regex.Replace(filterResult, naughtyWord, "****"); } } Print("Filtered message sample:\n" + filterResult); stopWatch.Stop(); ts = stopWatch.Elapsed; elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Print("Time: " + elapsedTime); Print("Messages/sec: " + (iters / ts.TotalSeconds)); }
public static void Main() { int iters = 1000; int dictSize = 1000; int msgLength = 100; Print("-- Begin filter benchmark --"); Print("Number of messages scanned: " + iters); Print("Wordlist size: " + dictSize); Print("Message length: " + msgLength); List <string> wordList = new List <string> (); for (int i = 0; i < (dictSize * 2); i += 2) { wordList.Add("" + i); } TrieFilter myTrie = new TrieFilter(wordList); Regex wordsRegex = new Regex(String.Join("|", wordList.ToArray()), RegexOptions.Compiled); string testMsg = ""; for (int i = 0; i < (msgLength / 5); i++) { testMsg = testMsg + "13579"; } // ----- Run the tests! ----- Print("\n-- START TRIE TEST --"); Print("Filtering " + iters + " messages..."); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < iters; i++) { myTrie.replaceAllWords(testMsg); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Print("Time: " + elapsedTime); Print("Messages/sec: " + (iters / ts.TotalSeconds)); // ----- Print("\n-- START OPTIMIZED REGEX TEST --"); Print("Filtering " + iters + " messages..."); stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < iters; i++) { wordsRegex.Replace(testMsg, "****"); } stopWatch.Stop(); ts = stopWatch.Elapsed; elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Print("Time: " + elapsedTime); Print("Messages/sec: " + (iters / ts.TotalSeconds)); // ----- Print("\n-- START PER-WORD REGEX TEST --"); Print("Filtering " + iters + " messages..."); stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < iters; i++) { foreach (string naughtyWord in wordList) { Regex.Replace(testMsg, naughtyWord, "****"); } } stopWatch.Stop(); ts = stopWatch.Elapsed; elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Print("Time: " + elapsedTime); Print("Messages/sec: " + (iters / ts.TotalSeconds)); }