Calculations in Recycler View Adapter, Will it affect performance?












0















My doubt is will there be a low performance if we perform calculations before setting data in the recycler view in Android?



For example, Im receiving list of data as a server response such as:




  • Sales target:50 and Sales target achieved:10 for Person A

  • Sales Target:60 and Sales Target Achieved:15 for Person B,etc..


and I have to show this in a recycler view along with Percentage,
So I do a calculation at Android side to convert these sales target into percentage before setting in the adapter. So before setting the first data, I calculate percentage by doing this: (10/50) *100, which gives me 20%,and so on, for all the list data. So does this calculation lower the performance of loading in Android or will it be better if I calculate the percentage in the server side and get the percentage in the response itself so that I can simply set it without any calculation, but will it affect response time?



So I'm in a confusion between Server Response Time and Android Processing time.










share|improve this question



























    0















    My doubt is will there be a low performance if we perform calculations before setting data in the recycler view in Android?



    For example, Im receiving list of data as a server response such as:




    • Sales target:50 and Sales target achieved:10 for Person A

    • Sales Target:60 and Sales Target Achieved:15 for Person B,etc..


    and I have to show this in a recycler view along with Percentage,
    So I do a calculation at Android side to convert these sales target into percentage before setting in the adapter. So before setting the first data, I calculate percentage by doing this: (10/50) *100, which gives me 20%,and so on, for all the list data. So does this calculation lower the performance of loading in Android or will it be better if I calculate the percentage in the server side and get the percentage in the response itself so that I can simply set it without any calculation, but will it affect response time?



    So I'm in a confusion between Server Response Time and Android Processing time.










    share|improve this question

























      0












      0








      0








      My doubt is will there be a low performance if we perform calculations before setting data in the recycler view in Android?



      For example, Im receiving list of data as a server response such as:




      • Sales target:50 and Sales target achieved:10 for Person A

      • Sales Target:60 and Sales Target Achieved:15 for Person B,etc..


      and I have to show this in a recycler view along with Percentage,
      So I do a calculation at Android side to convert these sales target into percentage before setting in the adapter. So before setting the first data, I calculate percentage by doing this: (10/50) *100, which gives me 20%,and so on, for all the list data. So does this calculation lower the performance of loading in Android or will it be better if I calculate the percentage in the server side and get the percentage in the response itself so that I can simply set it without any calculation, but will it affect response time?



      So I'm in a confusion between Server Response Time and Android Processing time.










      share|improve this question














      My doubt is will there be a low performance if we perform calculations before setting data in the recycler view in Android?



      For example, Im receiving list of data as a server response such as:




      • Sales target:50 and Sales target achieved:10 for Person A

      • Sales Target:60 and Sales Target Achieved:15 for Person B,etc..


      and I have to show this in a recycler view along with Percentage,
      So I do a calculation at Android side to convert these sales target into percentage before setting in the adapter. So before setting the first data, I calculate percentage by doing this: (10/50) *100, which gives me 20%,and so on, for all the list data. So does this calculation lower the performance of loading in Android or will it be better if I calculate the percentage in the server side and get the percentage in the response itself so that I can simply set it without any calculation, but will it affect response time?



      So I'm in a confusion between Server Response Time and Android Processing time.







      android performance android-recyclerview android-adapter






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 11:36









      Reejesh PKReejesh PK

      1081212




      1081212
























          2 Answers
          2






          active

          oldest

          votes


















          1














          The percentage seems to be not security-sensitive, you could calculate it on client side. If you want to save time on processing the data, try fill some data to the recycler view's adapter to make it visible to user, then perform some asynchronous
          background task to calculate the data and update the view.






          share|improve this answer
























          • Yeah, Async Task seems to be good, I didn't think of it. Thanks!

            – Reejesh PK
            Nov 25 '18 at 11:53



















          0














          You should use AsyncTask. It will do task in background thread and will update the UI accordingly.
          Below is a simple example:



          private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
          protected Long doInBackground(URL... urls) {
          int count = urls.length;
          long totalSize = 0;
          for (int i = 0; i < count; i++) {
          totalSize += Downloader.downloadFile(urls[i]);
          publishProgress((int) ((i / (float) count) * 100));
          // Escape early if cancel() is called
          if (isCancelled()) break;
          }
          return totalSize;
          }

          protected void onProgressUpdate(Integer... progress) {
          setProgressPercent(progress[0]);
          }

          protected void onPostExecute(Long result) {
          showDialog("Downloaded " + result + " bytes");
          }
          }


          To run AsyncTask



          new DownloadFilesTask(). execute(param1, param2, param3);


          To cancel task call



          cancel();





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467044%2fcalculations-in-recycler-view-adapter-will-it-affect-performance%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            The percentage seems to be not security-sensitive, you could calculate it on client side. If you want to save time on processing the data, try fill some data to the recycler view's adapter to make it visible to user, then perform some asynchronous
            background task to calculate the data and update the view.






            share|improve this answer
























            • Yeah, Async Task seems to be good, I didn't think of it. Thanks!

              – Reejesh PK
              Nov 25 '18 at 11:53
















            1














            The percentage seems to be not security-sensitive, you could calculate it on client side. If you want to save time on processing the data, try fill some data to the recycler view's adapter to make it visible to user, then perform some asynchronous
            background task to calculate the data and update the view.






            share|improve this answer
























            • Yeah, Async Task seems to be good, I didn't think of it. Thanks!

              – Reejesh PK
              Nov 25 '18 at 11:53














            1












            1








            1







            The percentage seems to be not security-sensitive, you could calculate it on client side. If you want to save time on processing the data, try fill some data to the recycler view's adapter to make it visible to user, then perform some asynchronous
            background task to calculate the data and update the view.






            share|improve this answer













            The percentage seems to be not security-sensitive, you could calculate it on client side. If you want to save time on processing the data, try fill some data to the recycler view's adapter to make it visible to user, then perform some asynchronous
            background task to calculate the data and update the view.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 25 '18 at 11:45









            XieEDeHeiShouXieEDeHeiShou

            1008




            1008













            • Yeah, Async Task seems to be good, I didn't think of it. Thanks!

              – Reejesh PK
              Nov 25 '18 at 11:53



















            • Yeah, Async Task seems to be good, I didn't think of it. Thanks!

              – Reejesh PK
              Nov 25 '18 at 11:53

















            Yeah, Async Task seems to be good, I didn't think of it. Thanks!

            – Reejesh PK
            Nov 25 '18 at 11:53





            Yeah, Async Task seems to be good, I didn't think of it. Thanks!

            – Reejesh PK
            Nov 25 '18 at 11:53













            0














            You should use AsyncTask. It will do task in background thread and will update the UI accordingly.
            Below is a simple example:



            private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
            protected Long doInBackground(URL... urls) {
            int count = urls.length;
            long totalSize = 0;
            for (int i = 0; i < count; i++) {
            totalSize += Downloader.downloadFile(urls[i]);
            publishProgress((int) ((i / (float) count) * 100));
            // Escape early if cancel() is called
            if (isCancelled()) break;
            }
            return totalSize;
            }

            protected void onProgressUpdate(Integer... progress) {
            setProgressPercent(progress[0]);
            }

            protected void onPostExecute(Long result) {
            showDialog("Downloaded " + result + " bytes");
            }
            }


            To run AsyncTask



            new DownloadFilesTask(). execute(param1, param2, param3);


            To cancel task call



            cancel();





            share|improve this answer






























              0














              You should use AsyncTask. It will do task in background thread and will update the UI accordingly.
              Below is a simple example:



              private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
              protected Long doInBackground(URL... urls) {
              int count = urls.length;
              long totalSize = 0;
              for (int i = 0; i < count; i++) {
              totalSize += Downloader.downloadFile(urls[i]);
              publishProgress((int) ((i / (float) count) * 100));
              // Escape early if cancel() is called
              if (isCancelled()) break;
              }
              return totalSize;
              }

              protected void onProgressUpdate(Integer... progress) {
              setProgressPercent(progress[0]);
              }

              protected void onPostExecute(Long result) {
              showDialog("Downloaded " + result + " bytes");
              }
              }


              To run AsyncTask



              new DownloadFilesTask(). execute(param1, param2, param3);


              To cancel task call



              cancel();





              share|improve this answer




























                0












                0








                0







                You should use AsyncTask. It will do task in background thread and will update the UI accordingly.
                Below is a simple example:



                private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
                protected Long doInBackground(URL... urls) {
                int count = urls.length;
                long totalSize = 0;
                for (int i = 0; i < count; i++) {
                totalSize += Downloader.downloadFile(urls[i]);
                publishProgress((int) ((i / (float) count) * 100));
                // Escape early if cancel() is called
                if (isCancelled()) break;
                }
                return totalSize;
                }

                protected void onProgressUpdate(Integer... progress) {
                setProgressPercent(progress[0]);
                }

                protected void onPostExecute(Long result) {
                showDialog("Downloaded " + result + " bytes");
                }
                }


                To run AsyncTask



                new DownloadFilesTask(). execute(param1, param2, param3);


                To cancel task call



                cancel();





                share|improve this answer















                You should use AsyncTask. It will do task in background thread and will update the UI accordingly.
                Below is a simple example:



                private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
                protected Long doInBackground(URL... urls) {
                int count = urls.length;
                long totalSize = 0;
                for (int i = 0; i < count; i++) {
                totalSize += Downloader.downloadFile(urls[i]);
                publishProgress((int) ((i / (float) count) * 100));
                // Escape early if cancel() is called
                if (isCancelled()) break;
                }
                return totalSize;
                }

                protected void onProgressUpdate(Integer... progress) {
                setProgressPercent(progress[0]);
                }

                protected void onPostExecute(Long result) {
                showDialog("Downloaded " + result + " bytes");
                }
                }


                To run AsyncTask



                new DownloadFilesTask(). execute(param1, param2, param3);


                To cancel task call



                cancel();






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 25 '18 at 14:00

























                answered Nov 25 '18 at 13:55









                Lekr0Lekr0

                357212




                357212






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467044%2fcalculations-in-recycler-view-adapter-will-it-affect-performance%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    To store a contact into the json file from server.js file using a class in NodeJS

                    Redirect URL with Chrome Remote Debugging Android Devices

                    Dieringhausen