Programming වැඩ්ඩොන්ගෙන් හෙල්ප් එකක්, Come here

BruceWayne92

Well-known member
  • Oct 8, 2013
    12,308
    1
    13,223
    113
    Gotham City
    අනිවා උබ programming වලට අලුත් එකෙක්.
    ඇත්තම කිව්වොත් මේක කිසිම තේරුමක් නැති ප්‍රශ්නයක්.

    software ලියනකොට speed එකට වඩා හිතන්න ඕන code maitainability, scalability ගැන.

    ඕව ගැන තර්ක කරන්න පුලුවන්. නමුත් ඕව ප්‍රායෝගිකව භාවිතා වෙන්නේ නැත්නම් සහ එහෙම කරන එකත් පිස්සුවක් නිසා.

    මේ වගේ ප්‍රශ්නත් තේරුමක් නැති ප්‍රශ්න.


    දීපාල් අයියා ලියන්නෙ උඹට එහෙමද ?? :baffled::lol::lol:
     
    • Like
    Reactions: sithija.h

    CustomerSupport

    Well-known member
  • Mar 21, 2016
    2,422
    1,548
    113
    අනිවා උබ programming වලට අලුත් එකෙක්.
    ඇත්තම කිව්වොත් මේක කිසිම තේරුමක් නැති ප්‍රශ්නයක්.

    software ලියනකොට speed එකට වඩා හිතන්න ඕන code maitainability, scalability ගැන.

    ඕව ගැන තර්ක කරන්න පුලුවන්. නමුත් ඕව ප්‍රායෝගිකව භාවිතා වෙන්නේ නැත්නම් සහ එහෙම කරන එකත් පිස්සුවක් නිසා.

    මේ වගේ ප්‍රශ්නත් තේරුමක් නැති ප්‍රශ්න.

    His personal arrogance aside, I'm rooting for this.

    Todays compilers/processors are smart enough to optimize loops. Technically, the latter is a O(1), and it should be faster. However, the compiler cannot predict and try to optimize it, where it knows the semantics of a loop and attempt to optimize it.

    There is absolutely no reason to do pointless micro optimizations like this. Obviously, don't do any file, database, network, etc stuff within a loop and look out for ways to optimize it. But the one you have is utterly pointless. In any modern computer, I bet you you wouldn't see at least 1 second difference for a million iterations.
     

    thilina91

    Member
    May 28, 2008
    18,560
    858
    0
    New World, Grand Line
    His personal arrogance aside, I'm rooting for this.

    Todays compilers/processors are smart enough to optimize loops. Technically, the latter is a O(1), and it should be faster. However, the compiler cannot predict and try to optimize it, where it knows the semantics of a loop and attempt to optimize it.

    There is absolutely no reason to do pointless micro optimizations like this. Obviously, don't do any file, database, network, etc stuff within a loop and look out for ways to optimize it. But the one you have is utterly pointless. In any modern computer, I bet you you wouldn't see at least 1 second difference for a million iterations.

    I think optimizations comes handy in embedded systems programming. Mostly because micro-controllers are not as powerful as CPU processors and have a low frequency to save up battery life.
     

    sithija.h

    Well-known member
  • Nov 21, 2008
    9,679
    5,904
    113
    Matara
    මම c++ නොදනිමි. එ හින්ද ඔය දෙකෙන් වඩිය ස්පීඩ් මොකක්ද බලන්න ජාවා වලින් ට්‍රයි කරා මෙන්න මෙහෙම.


    public class Loop {

    public static void main(String[] args) {

    long startTime = System.currentTimeMillis();

    int value = 0;
    while (value < 5)
    {
    System.out.println("Hello Elakiri..");
    value++;
    }

    long endTime = System.currentTimeMillis();
    System.out.println(endTime - startTime);
    }
    }


    මේ තියෙන්නෙ අර ලූප් එක තියෙන කෝඩ් එක. ඕකේ ඔය System.currentTimeMillis(); කියන මෙතඩ් එකෙන් කරන්නේ 1970-1-1 රෑ 12 ඉදන් මේ වෙනකන් ගියපු මිලිසෙකන්ඩ්ස් ගාන ගාන ගන්න එක.(වෙන්න ඇති)ප්‍රොග්‍රෑම් එක පටන් ගද්දි වෙලාවයි ඉවර වෙද්දි වෙලාවයි අරන් වෙනසෙන් ප්‍රොග්‍රෑම් එක රන් වෙන්න ගියපු කාලෙ අරන් අවසානෙට ප්‍රින්ට් වෙන්නයි තියේන්නේ. ඔය කෝඩ් එක රන් කරපුවාම අව රිසාල්ට් එක මෙන්න.

    Hello Elakiri..
    Hello Elakiri..
    Hello Elakiri..
    Hello Elakiri..
    Hello Elakiri..
    0



    (කාල වෙනස 0 යි )

    මේ පහල තියෙන්නෙ අර ස්ටේට්මන්ට් තියෙන කෝඩ් එක.


    public class Statement {

    public static void main(String[] args) {

    long startTime = System.currentTimeMillis();


    System.out.println("Hello Elakiri..");
    System.out.println("Hello Elakiri..");
    System.out.println("Hello Elakiri..");
    System.out.println("Hello Elakiri..");
    System.out.println("Hello Elakiri..");


    long endTime = System.currentTimeMillis();

    System.out.println(endTime - startTime);
    }
    }

    මෙන්න එකේ අපු රිසාල්ට් එක.

    Hello Elakiri..
    Hello Elakiri..
    Hello Elakiri..
    Hello Elakiri..
    Hello Elakiri..
    0


    (කාල වෙනස 0 යි )

    මේ කෝඩ් දෙක ගොඩක් පොඩි නිසා වැඩි වෙනසක් නෑ.නමුත් ජවා වල ArrayList & LinkedList වගේ ගත්තාම සමහර අවස්ථාවල පොඩි එනසක් තියෙනවා.


    https://dzone.com/articles/arraylist-vs-linkedlist-vs

    තෑන්ක්න් බං රිප්ලයි එකට, උඹ කිව්ව කන්සෙප්ට් එකෙන් මම මේ කෝඩ් එක වෙනස් කරලා, මේකෙ ප්‍රින්ටින් ලයින්ස් ගාන 1000ක් කරලා, Time Measuring Unit එක Nano Seconds කළා බං, එතකොට හරිම Answer එක ආවා බං, 2nd Program එක Fast බං,

    මෙන්න මට ආව Output එක,

    Time for first program in nanoseconds 65687864
    Time for Second Program in nanoseconds 16872494

    2වැනි Source Code එක Nano Seconds 48815370 ක් කළින් Execute වෙනවා බං, පළවෙනි එකට වඩා, ඒත් මේක User ට දැනෙන්නෙවත් නැති පොඩිම පොඩි අගයක් බං, මොකට 1Seconds = 1000000000 NanoSeconds

    එල බං,
     
    • Like
    Reactions: Bataya01

    Bataya01

    Well-known member
  • Sep 7, 2013
    1,639
    122
    63
    :sorry: මම ඒක තමා මචං කිව්වෙ. n^2 එනව වගේ මතකයි කියල මං quote කරපු reply එකේ තිබුන නිසා.
    මේ code දෙක සංසංදනය කරනවා නම් බං 2nd code එකේ එක O(m) වගේ එකක් තමයි කියන්න වෙන්නෙ. constant time කියන්න බෑ නේද මචං. එක line එකක් වෙනම ගත්තොත් O(1). ඒත් මෙතන බලන්නෙ එකම lines ගාන print කරද්දිනෙ.මං වැරදිනම් කියපං මචන්.
     
    Last edited:
    • Like
    Reactions: sithija.h

    Sonique

    Well-known member
  • Oct 22, 2007
    25,197
    11,223
    113
    Forest
    Second one is fast but takes a lot of memory since there are 5 seperate char arrays. When you program like that for a chip with low Flash Memory (EDITED) soon you will run out of memory and it becomes unstable. But for a PC with a huge ROM it is not a problem :)
     
    Last edited:

    CustomerSupport

    Well-known member
  • Mar 21, 2016
    2,422
    1,548
    113
    I think optimizations comes handy in embedded systems programming. Mostly because micro-controllers are not as powerful as CPU processors and have a low frequency to save up battery life.
    It's not like they can run huge byte code either ne machan. You are likely to run out of memory with a large byte code.
     
    • Like
    Reactions: sithija.h

    thilina91

    Member
    May 28, 2008
    18,560
    858
    0
    New World, Grand Line
    It's not like they can run huge byte code either ne machan. You are likely to run out of memory with a large byte code.

    Yeah true that. But they aren't used for doing this kind of tasks though.
    But I've programmed arduinos with for loops that run perfectly well.
    Loops were the easiest when we programmed a PIC in assembly. Otherwise we would have to write a crap load of code.:dull:
     
    • Like
    Reactions: sithija.h

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,974
    1
    9,793
    113
    Gampaha
    Second one is fast but takes a lot of memory since there are 5 seperate char arrays. When you program like that for a chip with low EEPROM soon you will run out of memory and it becomes unstable. But for a PC with a huge ROM it is not a problem :)
    :shocked: TFS danagena hitiye na mehema ekak.. :cool: 14+
     
    • Like
    Reactions: sithija.h

    Sonique

    Well-known member
  • Oct 22, 2007
    25,197
    11,223
    113
    Forest
    :shocked: TFS danagena hitiye na mehema ekak.. :cool: 14+

    එල මචන්. පොඩි programmable memory එකක් තියන chip එකක් එක්ක ලොකු project එකක් කරන්න සෙට් වෙන්න එතකොට EEPROM, SRAM, DRAM, Flash Memory, Heap, Stack ඉගෙන ගන්නවා. පොඩ්ඩක් කලින් කියපු එක වැරදුනා. EEPROM එකේ ප්‍රශ්නේ වෙන එකක්. Flash Memory එකයි Ram එකයි over use වෙන්නේ. Sorry. EEPROM එකේ ප්‍රශ්නේ ආවේ non volatile storage එකක් use කරන්න යද්දී display එහෙක background එකකට. හැබැයි දෙකම එකම කතාව. Edited:)
     
    Last edited:

    DJ_HarDWelL

    Well-known member
  • Jul 31, 2016
    871
    155
    63
    127.0.0.1
    තෑන්ක්න් බං රිප්ලයි එකට, උඹ කිව්ව කන්සෙප්ට් එකෙන් මම මේ කෝඩ් එක වෙනස් කරලා, මේකෙ ප්‍රින්ටින් ලයින්ස් ගාන 1000ක් කරලා, Time Measuring Unit එක Nano Seconds කළා බං, එතකොට හරිම Answer එක ආවා බං, 2nd Program එක Fast බං,

    මෙන්න මට ආව Output එක,

    Time for first program in nanoseconds 65687864
    Time for Second Program in nanoseconds 16872494

    2වැනි Source Code එක Nano Seconds 48815370 ක් කළින් Execute වෙනවා බං, පළවෙනි එකට වඩා, ඒත් මේක User ට දැනෙන්නෙවත් නැති පොඩිම පොඩි අගයක් බං, මොකට 1Seconds = 1000000000 NanoSeconds

    එල බං,

    පට්ට මචන්. ඔය තියෙන්නෙ සාර්ථක පාලක සහ පාලිත පරික්ශනයක්. :yes::yes::yes::yes:
     

    CorD SaC

    Well-known member
  • Feb 4, 2015
    15,774
    28,148
    113
    පට්ට මචන්. ඔය තියෙන්නෙ සාර්ථක පාලක සහ පාලිත පරික්ශනයක්. :yes::yes::yes::yes:

    ඒ කියන්නේ මචන්... :confused:
    ලැජ්ජයි සිංහල වෙලා මෙහෙම අහන්ඩ උන එක ගැන, :( ඒත් කමක් නෑ මොකක්ද ඒ :)
     

    sithija.h

    Well-known member
  • Nov 21, 2008
    9,679
    5,904
    113
    Matara
    පට්ට මචන්. ඔය තියෙන්නෙ සාර්ථක පාලක සහ පාලිත පරික්ශනයක්. :yes::yes::yes::yes:


    ඒ කියන්නේ මචන්... :confused:
    ලැජ්ජයි සිංහල වෙලා මෙහෙම අහන්ඩ උන එක ගැන, :( ඒත් කමක් නෑ මොකක්ද ඒ :)

    මටත් ඒක තේරුනේ නෑ බං