Microoptimization

master
Inga 🏳‍🌈 8 years ago
parent b667aa8830
commit 5ffaa1090a
  1. 15
      dotnet/WhiteRabbit/PhraseSet.cs
  2. 2
      dotnet/WhiteRabbit/Program.cs
  3. 8
      dotnet/WhiteRabbit/StringsProcessor.cs

@ -10,21 +10,18 @@
{ {
private uint[] Buffer; private uint[] Buffer;
public int Length; public void Init()
public PhraseSet(int length)
{ {
this.Length = length; this.Buffer = new uint[8 * Constants.PhrasesPerSet];
this.Buffer = new uint[8 * length];
} }
public unsafe void InitPhraseSet(int numberOfCharacters, int numberOfWords) public unsafe void FillLength(int numberOfCharacters, int numberOfWords)
{ {
fixed (uint* bufferPointer = this.Buffer) fixed (uint* bufferPointer = this.Buffer)
{ {
var length = (uint)(numberOfCharacters + numberOfWords - 1); var length = (uint)(numberOfCharacters + numberOfWords - 1);
var lengthInBits = (uint)(length << 3); var lengthInBits = (uint)(length << 3);
for (var i = 0; i < this.Length; i++) for (var i = 0; i < Constants.PhrasesPerSet; i++)
{ {
bufferPointer[7 + i * 8] = lengthInBits; bufferPointer[7 + i * 8] = lengthInBits;
((byte*)bufferPointer)[length + i * 32] = 128 ^ ' '; ((byte*)bufferPointer)[length + i * 32] = 128 ^ ' ';
@ -71,7 +68,7 @@
public unsafe byte[] GetBytes(int number) public unsafe byte[] GetBytes(int number)
{ {
Debug.Assert(number < this.Length); Debug.Assert(number < Constants.PhrasesPerSet);
fixed (uint* bufferPointer = this.Buffer) fixed (uint* bufferPointer = this.Buffer)
{ {
@ -98,7 +95,7 @@
public unsafe string DebugBytes(int number) public unsafe string DebugBytes(int number)
{ {
Debug.Assert(number < this.Length); Debug.Assert(number < Constants.PhrasesPerSet);
fixed (uint* bufferPointer = this.Buffer) fixed (uint* bufferPointer = this.Buffer)
{ {

@ -86,7 +86,7 @@
private static void ProcessPhraseSet(PhraseSet phraseSet, Vector<uint> expectedHashesFirstComponents, Stopwatch stopwatch) private static void ProcessPhraseSet(PhraseSet phraseSet, Vector<uint> expectedHashesFirstComponents, Stopwatch stopwatch)
{ {
phraseSet.ComputeMD5(); phraseSet.ComputeMD5();
for (var i = 0; i < phraseSet.Length; i++) for (var i = 0; i < Constants.PhrasesPerSet; i++)
{ {
/*Debug.Assert( /*Debug.Assert(
sourceChars == ToOrderedChars(ToString(phraseSet, i)), sourceChars == ToOrderedChars(ToString(phraseSet, i)),

@ -120,9 +120,11 @@
private void ProcessSum(int[] sum, Action<PhraseSet> action) private void ProcessSum(int[] sum, Action<PhraseSet> action)
{ {
var initialPhraseSet = new PhraseSet(Constants.PhrasesPerSet); var initialPhraseSet = new PhraseSet();
initialPhraseSet.InitPhraseSet(this.NumberOfCharacters, sum.Length); initialPhraseSet.Init();
var phraseSet = new PhraseSet(Constants.PhrasesPerSet); initialPhraseSet.FillLength(this.NumberOfCharacters, sum.Length);
var phraseSet = new PhraseSet();
phraseSet.Init();
var filter = ComputeFilter(sum); var filter = ComputeFilter(sum);
var wordsVariants = this.ConvertVectorsToWordIndexes(sum); var wordsVariants = this.ConvertVectorsToWordIndexes(sum);
foreach (var wordsArray in Flattener.Flatten(wordsVariants)) foreach (var wordsArray in Flattener.Flatten(wordsVariants))

Loading…
Cancel
Save