Skip to content

Instantly share code, notes, and snippets.

@totalgee
Last active February 24, 2022 12:09
Show Gist options
  • Select an option

  • Save totalgee/640805cb8995cf588152 to your computer and use it in GitHub Desktop.

Select an option

Save totalgee/640805cb8995cf588152 to your computer and use it in GitHub Desktop.

Revisions

  1. totalgee revised this gist Feb 24, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -112,14 +112,14 @@ from timeit import default_timer as timer

    sum = 0.0
    start = timer()
    for i in xrange(1, 100001):
    for i in range(1, 100001):
    if i % 2 == 0:
    sum += 1.0 / float(i)
    else:
    sum += 1.0 / (float(i) * i)

    end = timer()
    print "Elapsed time: {:.6f} sum: {:.4f}".format(end - start, sum)
    print("Elapsed time: {:.6f} sum: {:.4f}".format(end - start, sum))

    //
    // Python v2.7.6 (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
  2. totalgee revised this gist May 6, 2015. 1 changed file with 12 additions and 10 deletions.
    22 changes: 12 additions & 10 deletions ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -20,23 +20,25 @@ ChaiScript v5.6.0+ (8fc61bf) 0.4949 176.8
    ////////////////////////////////////////////////////////////
    // ChaiScript:
    //
    // getTimeInSeconds() is implemented in C++ as follows:
    // There is a performance unit test that runs this code; you can run it several
    // times to get the best run, like this (from the cmake build directory):
    // $ (for i in {1..25}; do echo "Testing $i" 1>&2; ctest -R performance -V | grep Elapsed; done) | sort | head -1
    //
    // double getTimeInSeconds()
    // {
    // using namespace std::chrono;
    // static time_point<high_resolution_clock> start = high_resolution_clock::now();
    // now() is implemented in C++ as follows:
    //
    // duration<double> elapsed_seconds = high_resolution_clock::now() - start;
    // return elapsed_seconds.count();
    // double now()
    // {
    // using namespace std::chrono;
    // auto now = high_resolution_clock::now();
    // return duration_cast<duration<double>>(now.time_since_epoch()).count();
    // }
    //
    // It is exposed as follows:
    //
    // mChai.add(chaiscript::fun(&getTimeInSeconds), "getTimeInSeconds");
    // mChai.add(chaiscript::fun(&now), "now");

    var sum = 0.0
    var start = getTimeInSeconds()
    var start = now()
    for (var i = 1; i <= 100000; ++i) {
    if (i % 2 == 0) {
    sum += 1.0 / i;
    @@ -45,7 +47,7 @@ for (var i = 1; i <= 100000; ++i) {
    sum += 1.0 / (double(i) * i);
    }
    }
    var end = getTimeInSeconds()
    var end = now()
    print("Elapsed time: " + to_string(end - start) + " sum: " + to_string(sum))

    //
  3. totalgee revised this gist May 5, 2015. 1 changed file with 15 additions and 11 deletions.
    26 changes: 15 additions & 11 deletions ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,20 @@
    Summary for simple looped calculation (details and code below):
    - on OS X 10.10.3, Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5

    Language Tested Version Best Time Relative to Fastest
    ======== ============== ========= ===================
    Language Tested Version Best Time Relative Perf Notes
    ======== ============== ========= ============= =====
    Node.js v0.10.33 0.0028 1
    Lua v5.3.0 0.0098 3.5
    SuperCollider v3.6.6 0.0138 4.9
    Ruby v2.0.0p481 0.0143 5.1
    Python v2.7.6 0.0413 14.8
    ChaiScript v5.6.0+ (fdcc595) 0.1898 67.8
    (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc; 15% improvement compared to ebc6468)
    ChaiScript v5.6.0+ (ebc6468) 0.2246 80.2
    (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc)
    ChaiScript v5.6.0+ (fdcc595) 0.2493 89.0
    (compiled w/ -DCHAISCRIPT_NO_THREADS; this commit has a 25% speed improvement compared to ebc6468)
    ChaiScript v5.6.0+ (ebc6468) 0.3325 118.8
    (compiled w/ -DCHAISCRIPT_NO_THREADS)
    ChaiScript v5.6.0+ (fdcc595) 0.1898 67.8 -DCHAISCRIPT_NO_THREADS -ltcmalloc
    ChaiScript v5.6.0+ (ebc6468) 0.2246 80.2 -DCHAISCRIPT_NO_THREADS -ltcmalloc
    ChaiScript v5.6.0+ (fdcc595) 0.2493 89.0 -DCHAISCRIPT_NO_THREADS
    ChaiScript v5.6.0+ (ebc6468) 0.3325 118.8 -DCHAISCRIPT_NO_THREADS
    ChaiScript v5.6.0+ (fdcc595) 0.3599 128.5 -ltcmalloc
    ChaiScript v5.6.0+ (fdcc595) 0.4206 150.2
    ChaiScript v5.6.0+ (8fc61bf) 0.4949 176.8
    (compiled w/ thread-safety enabled; default)


    ////////////////////////////////////////////////////////////
    @@ -71,6 +68,13 @@ print("Elapsed time: " + to_string(end - start) + " sum: " + to_string(sum))
    // ChaiScript v5.6.0+ (fdcc595) Release (measured May 5, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with -ltcmalloc_minimal; 15% improvement compared to ebc6468)
    // Elapsed time: 0.18984 sum: 6.9322
    //
    // ChaiScript v5.6.0+ (fdcc595) Release (measured May 5, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (linked with -ltcmalloc_minimal)
    // Elapsed time: 0.359919 sum: 6.9322
    //
    // ChaiScript v5.6.0+ (fdcc595) Release (measured May 5, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.420597 sum: 6.9322



  4. totalgee revised this gist May 5, 2015. 1 changed file with 18 additions and 6 deletions.
    24 changes: 18 additions & 6 deletions ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -8,11 +8,15 @@ Lua v5.3.0 0.0098 3.5
    SuperCollider v3.6.6 0.0138 4.9
    Ruby v2.0.0p481 0.0143 5.1
    Python v2.7.6 0.0413 14.8
    ChaiScript post-v5.6.0 (ebc6468) 0.2246 80.2
    ChaiScript v5.6.0+ (fdcc595) 0.1898 67.8
    (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc; 15% improvement compared to ebc6468)
    ChaiScript v5.6.0+ (ebc6468) 0.2246 80.2
    (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc)
    ChaiScript post-v5.6.0 (ebc6468) 0.3325 118.8
    ChaiScript v5.6.0+ (fdcc595) 0.2493 89.0
    (compiled w/ -DCHAISCRIPT_NO_THREADS; this commit has a 25% speed improvement compared to ebc6468)
    ChaiScript v5.6.0+ (ebc6468) 0.3325 118.8
    (compiled w/ -DCHAISCRIPT_NO_THREADS)
    ChaiScript post-v5.6.0 (8fc61bf) 0.4949 176.8
    ChaiScript v5.6.0+ (8fc61bf) 0.4949 176.8
    (compiled w/ thread-safety enabled; default)


    @@ -48,17 +52,25 @@ var end = getTimeInSeconds()
    print("Elapsed time: " + to_string(end - start) + " sum: " + to_string(sum))

    //
    // ChaiScript post-v5.6.0 (8fc61bf) Release (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // ChaiScript v5.6.0+ (8fc61bf) Release (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.494943 sum: 6.9322
    //
    // ChaiScript post-v5.6.0 (ebc6468) Release (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // ChaiScript v5.6.0+ (ebc6468) Release (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS)
    // Elapsed time: 0.332631 sum: 6.9322
    //
    // ChaiScript post-v5.6.0 (ebc6468) Release (measured May 4, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // ChaiScript v5.6.0+ (ebc6468) Release (measured May 4, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc: -ltcmalloc_minimal)
    // (TCMalloc is from gperftools v2.4)
    // Elapsed time: 0.224560 sum: 6.9322
    //
    // ChaiScript v5.6.0+ (fdcc595) Release (measured May 5, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS; this commit has a 25% speed improvement compared to ebc6468
    // Elapsed time: 0.249339 sum: 6.9322
    //
    // ChaiScript v5.6.0+ (fdcc595) Release (measured May 5, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with -ltcmalloc_minimal; 15% improvement compared to ebc6468)
    // Elapsed time: 0.18984 sum: 6.9322



  5. totalgee revised this gist May 5, 2015. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@ Language Tested Version Best Time Relative to Fastest
    Node.js v0.10.33 0.0028 1
    Lua v5.3.0 0.0098 3.5
    SuperCollider v3.6.6 0.0138 4.9
    Ruby v2.0.0p481 0.0143 5.1
    Python v2.7.6 0.0413 14.8
    ChaiScript post-v5.6.0 (ebc6468) 0.2246 80.2
    (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc)
    @@ -150,3 +151,25 @@ console.log('Elapsed time: %d sum: %d', elapsedSecs.toFixed(6), sum.toFixed(4));
    // Node.js v0.10.33 (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.002819 sum: 6.9322



    ////////////////////////////////////////////////////////////
    // Ruby:

    require "benchmark"
    sum = 0.0
    elapsed = Benchmark.realtime do
    for i in (1..100000)
    if i % 2 == 0 then
    sum = sum + 1.0 / i
    else
    sum = sum + 1.0 / (i * i)
    end
    end
    end
    puts "Elapsed time: %.6f sum: %.4f" % [elapsed, sum]

    //
    // Ruby v2.0.0p481 (measured May 5, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.014348 sum: 6.9322

  6. totalgee revised this gist May 4, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ Node.js v0.10.33 0.0028 1
    Lua v5.3.0 0.0098 3.5
    SuperCollider v3.6.6 0.0138 4.9
    Python v2.7.6 0.0413 14.8
    ChaiScript post-v5.6.0 (ebc6468) 0.2250 80.4
    ChaiScript post-v5.6.0 (ebc6468) 0.2246 80.2
    (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc)
    ChaiScript post-v5.6.0 (ebc6468) 0.3325 118.8
    (compiled w/ -DCHAISCRIPT_NO_THREADS)
    @@ -57,7 +57,7 @@ print("Elapsed time: " + to_string(end - start) + " sum: " + to_string(sum))
    // ChaiScript post-v5.6.0 (ebc6468) Release (measured May 4, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc: -ltcmalloc_minimal)
    // (TCMalloc is from gperftools v2.4)
    // Elapsed time: 0.2250 sum: 6.9322
    // Elapsed time: 0.224560 sum: 6.9322



  7. totalgee revised this gist May 4, 2015. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,9 @@ Node.js v0.10.33 0.0028 1
    Lua v5.3.0 0.0098 3.5
    SuperCollider v3.6.6 0.0138 4.9
    Python v2.7.6 0.0413 14.8
    ChaiScript post-v5.6.0 (8fc61bf) 0.3325 118.8
    ChaiScript post-v5.6.0 (ebc6468) 0.2250 80.4
    (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc)
    ChaiScript post-v5.6.0 (ebc6468) 0.3325 118.8
    (compiled w/ -DCHAISCRIPT_NO_THREADS)
    ChaiScript post-v5.6.0 (8fc61bf) 0.4949 176.8
    (compiled w/ thread-safety enabled; default)
    @@ -51,6 +53,11 @@ print("Elapsed time: " + to_string(end - start) + " sum: " + to_string(sum))
    // ChaiScript post-v5.6.0 (ebc6468) Release (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS)
    // Elapsed time: 0.332631 sum: 6.9322
    //
    // ChaiScript post-v5.6.0 (ebc6468) Release (measured May 4, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS and linked with TCMalloc: -ltcmalloc_minimal)
    // (TCMalloc is from gperftools v2.4)
    // Elapsed time: 0.2250 sum: 6.9322



  8. totalgee revised this gist Apr 30, 2015. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,10 @@ Node.js v0.10.33 0.0028 1
    Lua v5.3.0 0.0098 3.5
    SuperCollider v3.6.6 0.0138 4.9
    Python v2.7.6 0.0413 14.8
    ChaiScript post-v5.6.0 (8fc61bf) 0.3325 118.8
    (compiled w/ -DCHAISCRIPT_NO_THREADS)
    ChaiScript post-v5.6.0 (8fc61bf) 0.4949 176.8

    (compiled w/ thread-safety enabled; default)


    ////////////////////////////////////////////////////////////
    @@ -45,6 +47,10 @@ print("Elapsed time: " + to_string(end - start) + " sum: " + to_string(sum))
    //
    // ChaiScript post-v5.6.0 (8fc61bf) Release (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.494943 sum: 6.9322
    //
    // ChaiScript post-v5.6.0 (ebc6468) Release (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // (compiled w/ -DCHAISCRIPT_NO_THREADS)
    // Elapsed time: 0.332631 sum: 6.9322



  9. totalgee revised this gist Apr 30, 2015. 1 changed file with 36 additions and 0 deletions.
    36 changes: 36 additions & 0 deletions ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,15 @@
    Summary for simple looped calculation (details and code below):
    - on OS X 10.10.3, Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5

    Language Tested Version Best Time Relative to Fastest
    ======== ============== ========= ===================
    Node.js v0.10.33 0.0028 1
    Lua v5.3.0 0.0098 3.5
    SuperCollider v3.6.6 0.0138 4.9
    Python v2.7.6 0.0413 14.8
    ChaiScript post-v5.6.0 (8fc61bf) 0.4949 176.8



    ////////////////////////////////////////////////////////////
    // ChaiScript:
    @@ -101,3 +113,27 @@ print(string.format("Elapsed time: %.6f sum: %.4f", endTime-startTime, sum))
    //
    // Lua v5.3.0 (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.009793 sum: 6.9322



    ////////////////////////////////////////////////////////////
    // Node.js (Javascript):

    var sum = 0.0;
    var start = process.hrtime();
    for (var i = 1; i <= 100000; ++i) {
    if (i % 2 == 0) {
    sum += 1.0 / i;
    }
    else {
    sum += 1.0 / (i * i);
    }
    }
    var elapsed = process.hrtime(start);
    var elapsedSecs = elapsed[0] + elapsed[1] * 1e-9;
    console.log('Elapsed time: %d sum: %d', elapsedSecs.toFixed(6), sum.toFixed(4));

    //
    // Node.js v0.10.33 (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.002819 sum: 6.9322

  10. totalgee created this gist Apr 30, 2015.
    103 changes: 103 additions & 0 deletions ScriptPerformanceComparisons.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,103 @@

    ////////////////////////////////////////////////////////////
    // ChaiScript:
    //
    // getTimeInSeconds() is implemented in C++ as follows:
    //
    // double getTimeInSeconds()
    // {
    // using namespace std::chrono;
    // static time_point<high_resolution_clock> start = high_resolution_clock::now();
    //
    // duration<double> elapsed_seconds = high_resolution_clock::now() - start;
    // return elapsed_seconds.count();
    // }
    //
    // It is exposed as follows:
    //
    // mChai.add(chaiscript::fun(&getTimeInSeconds), "getTimeInSeconds");

    var sum = 0.0
    var start = getTimeInSeconds()
    for (var i = 1; i <= 100000; ++i) {
    if (i % 2 == 0) {
    sum += 1.0 / i;
    }
    else {
    sum += 1.0 / (double(i) * i);
    }
    }
    var end = getTimeInSeconds()
    print("Elapsed time: " + to_string(end - start) + " sum: " + to_string(sum))

    //
    // ChaiScript post-v5.6.0 (8fc61bf) Release (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.494943 sum: 6.9322



    ////////////////////////////////////////////////////////////
    // SuperCollider:

    (
    var sum = 0.0;
    var dur;
    dur = {
    (1..100000).do { arg i;
    if (i % 2 == 0) {
    sum = sum + (1.0 / i);
    } {
    sum = sum + (1.0 / (i * i));
    }
    };
    }.bench(false);
    "Elapsed time: % sum: %".format(dur.round(1e-6), sum.round(1e-4)).postln;
    ""
    )

    //
    // SuperCollider v3.6.6 (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.013837 sum: 6.9322



    ////////////////////////////////////////////////////////////
    // Python:

    from timeit import default_timer as timer

    sum = 0.0
    start = timer()
    for i in xrange(1, 100001):
    if i % 2 == 0:
    sum += 1.0 / float(i)
    else:
    sum += 1.0 / (float(i) * i)

    end = timer()
    print "Elapsed time: {:.6f} sum: {:.4f}".format(end - start, sum)

    //
    // Python v2.7.6 (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.041317 sum: 6.9322



    ////////////////////////////////////////////////////////////
    // Lua:

    sum = 0.0
    startTime = os.clock()
    for i = 1, 100000 do
    if i % 2 == 0 then
    sum = sum + (1.0 / i)
    else
    sum = sum + (1.0 / (i * i))
    end
    end
    endTime = os.clock()
    print(string.format("Elapsed time: %.6f sum: %.4f", endTime-startTime, sum))

    //
    // Lua v5.3.0 (measured April 30, 2015 on Mac Pro: 3,7 GHz Quad-Core Intel Xeon E5):
    // Elapsed time: 0.009793 sum: 6.9322