This is a list of sample LINQ queries and how they look when passed through FtLinq. The outputs were created by making a dynamic assembly from the generated light-weight functions and then decompiling it with ILSpy.

Select, SelectMany, Where

Original:
(int[] source) => source
                .Where(i => i < 90)
                .SelectMany(i => Enumerable.Repeat(i, 3))
                .Where(i => i % 2 == 0)
                .Select(i => i * 3)
                .ToList()


FtLinq version:
	List<int> list = new List<int>();
	for (int i = 0; i < source.Length; i++)
	{
		int num = source[i];
		if (num < 90)
		{
			IEnumerable<int> enumerable = Enumerable.Repeat<int>(num, 3);
			IEnumerator<int> enumerator = enumerable.GetEnumerator();
			while (enumerator.MoveNext())
			{
				int current = enumerator.Current;
				if (current % 2 == 0)
				{
					int item = current * 3;
					list.Add(item);
				}
			}
		}
	}
	return list;


Speed-up: 6.8x

SelectMany, GroupBy

Original:
(int[] source) =>
                source
                .Where(i => i < 90)
                .SelectMany(i => new[] { i * 2, i * 3, i * 4})
                .GroupBy(i => i % 2)


FtLinq version:
Dictionary<int, Grouping<int, int>> dictionary = new Dictionary<int, Grouping<int, int>>();
	for (int i = 0; i < source.Length; i++)
	{
		int num = source[i];
		if (num < 90)
		{
			int[] array = new int[]
			{
				num * 2,
				num * 3,
				num * 4
			};
			for (int j = 0; j < array.Length; j++)
			{
				int num2 = array[j];
				int key = num2 % 2;
				Grouping<int, int> grouping;
				if (!dictionary.TryGetValue(key, out grouping))
				{
					grouping = new Grouping<int, int>(key);
					dictionary.Add(key, grouping);
				}
				grouping.Add(num2);
			}
		}
	}
	return dictionary.Values;


Speed-up: 1.8x

Last edited Jun 16, 2012 at 11:26 AM by tailsu, version 2

Comments

No comments yet.