Encoding in 1, 2, and 4 Cores - More Cores == More Speed?

From R.A.M's blog, I've decided to test my 64-bit Quad-Core machine to encode some videos using Expression Encoder SDK.

Note that if you use Encoder SDK in 64-bit machines, you will get error "Could not load file or assembly 'Microsoft.Expression.Encoder"

This is how you solve it, go to your Build Properties and change the Platform to x86:

ScreenShot008 

So here are the results of encoding in 1,2, and 4 cores (I didn't test for 3 cores since I haven't heard of a Tri-Core CPU), but using my code below, you can certainly run it on 3 cores (weirdo :P)

ScreenShot004

ScreenShot005

01

So to conclude, the stats are:

Video File Size = 4MB
1 Core
Encoding = 39 seconds
2 Core Encoding = 24 seconds
4 Core Encoding = 17 seconds

So YES, MORE CORE MEANS FASTER ENCODING (my point of view, and Intel Marketing Guys will jump ecstatic in agreement).

And here's the code to throttle the application to run under X amount of Cores. Note that this code WILL ONLY WORK ON SINGLE-THREADED APPLICATION. For multi-threaded apps, I leave that to some future (hopefully I have time) post.

I used the Win32 Timer to measure the running time, you can see ZeddyLabs.TimerAkurat from this post.

class Program
{
    [Flags]
    public enum Cores : int
    {
        Core1 = 1,
        Core2 = 2,
        Core3 = 4,
        Core4 = 8
    }

    static Dictionary<int, Cores> GetCoresTable()
    {
        // I don't like too many IF-THEN-ELSE
        // hence the use of lookup table
        var table = new Dictionary<int, Cores>();
        table[1] = Cores.Core1;
        table[2] = table[1] | Cores.Core2;
        table[3] = table[2] | Cores.Core3;
        table[4] = table[3] | Cores.Core4;
        return table;
    }

    static int GetCoresCount(string[] args)
    {
        if (args.Length != 1)
        {
            Console.WriteLine("Please enter ONE numeric argument");
            Console.WriteLine("Usage: EncodeMultiCore <num>");
            Environment.Exit(-1);
        }

        int numValue;
        if (!int.TryParse(args[0], out numValue))
        {
            Console.WriteLine("Numeric argument cannot be parsed to integer");
            Environment.Exit(-1);
        }

        return numValue;
    }
    
    static void TestEncode()
    {
        // From Risman Adnan's blog
        const string video =
            @"C:\Users\Public\Videos\Sample Videos\Bear.wmv";

        var mediaItem = new MediaItem(video);

        // Create job & add the media item to it
        var job = new Job();
        job.MediaItems.Add(mediaItem);

        job.EncodeProgress +=
            ((sender, e) => Console.WriteLine(e.Progress));

        job.OutputDirectory = @"C:\temp";
        job.Encode();
    }

    static void Main(string[] args)
    {
        int cores = GetCoresCount(args);
        Dictionary<int, Cores> table = GetCoresTable();

        int coresToRun = (int)table[cores];

        Process.GetCurrentProcess()
            .ProcessorAffinity = (IntPtr) coresToRun;

        var timer = new ZeddyLabs.TimerAkurat();
        timer.Mulai();
            TestEncode();
        timer.Berhenti();

        Console.WriteLine("Dengan {0} core, encode memakan waktu {1} milidetik",
                          cores, timer.HasilDlmMilliDetik);

    }
}

Or you can download the codes from my SkyDrive below:

Share this post: | | | |
Published Wednesday, October 08, 2008 1:12 AM by zeddy

Comments

# re: Encoding in 1, 2, and 4 Cores - More Cores == More Speed?

Wednesday, October 08, 2008 9:05 AM by Risman Adnan

Zeddy, lu manas2in gw aja untuk beli Quad Core, dan berhasil kayaknya :).

Trus, apakah SDK nya Expression Encoder udah multi-core ready as noted in the documentation? Please test if you have time :).

# re: Encoding in 1, 2, and 4 Cores - More Cores == More Speed?

Wednesday, October 08, 2008 1:05 PM by zeddy

@Pa Risman: Bos, Expression Encoder udah multi-core ready, kalo kita nggak set Processor Affinity-nya, dia otomatis langsung menggunakan Max. No. of Available Cores. Makanya di screenshot Pak Risman juga CPU usage untuk 2 Core-nya naik kan waktu encoding...

Sayangnya Encoder SDK belum 64-bit compatible... masih 32-bit. Mungkin bisa ngaruh di performance, mengingat karena 32-bit cuman bisa akses 3GB RAM (1GB reserved oleh BIOS & hardware), sedangkan PC gw punya 8GB RAM.

Mau beli QuadCore? Atur aja Jendral kapan kita shopping ke Mangga2.

Powered by Community Server (Commercial Edition), by Telligent Systems