anchao commented on PR #15603:
URL: https://github.com/apache/nuttx/pull/15603#issuecomment-2604258856

   
   > i guess the main disagreement between us is on how large the overhead is. 
anchao seems to think it important. i feel it's negligible. none of us provided 
any numbers. maybe i can do some simple benchmark later.
   
   
   read test on sim/nsh ubuntu 24.04:
   
   with your patch:
   ```
   nsh> hello
   1:spending 0.32481253s
   2:spending 0.27835136s
   3:spending 0.27868075s
   4:spending 0.28006217s
   5:spending 0.28170945s
   6:spending 0.28187716s
   7:spending 0.27935934s
   8:spending 0.28042121s
   9:spending 0.28044079s
   10:spending 0.28143881s
   nsh> 
   ```
   
   with out your patch( -18% ):
   ```
   nsh> hello
   1:spending 0.28144562s
   2:spending 0.23062825s
   3:spending 0.23596239s
   4:spending 0.23038298s
   5:spending 0.22734277s
   6:spending 0.22969430s
   7:spending 0.22879461s
   8:spending 0.22730887s
   9:spending 0.22585802s
   10:spending 0.22629238s
   nsh> 
   ```
   
   test code:
   
   ```
   static void timespec_sub(struct timespec *dest,                            
                            struct timespec *ts1,                             
                            struct timespec *ts2)                             
   {                                                                          
     dest->tv_sec = ts1->tv_sec - ts2->tv_sec;                                
     dest->tv_nsec = ts1->tv_nsec - ts2->tv_nsec;                             
                                                                              
     if (dest->tv_nsec < 0)                                                   
       {                                                                      
         dest->tv_nsec += 1000000000;                                         
         dest->tv_sec -= 1;                                                   
       }                                                                      
   }                                                                          
                                                                              
                                                                              
   int main(int argc, FAR char *argv[])                                       
   {                                                                          
     struct timespec result;                                                  
     struct timespec start;                                                   
     struct timespec end;                                                     
     int fd = open("/dev/zero", O_RDONLY);                                    
     int loop = 0;                                                            
     int i = 0;                                                               
     char c;                                                                  
                                                                              
     while (loop++ < 10)                                                      
       {                                                                      
         i = 0;
         clock_gettime(CLOCK_MONOTONIC, &start);                              
         while (i++ < 100000)                                                 
           {                                                                  
             read(fd, &c, 1);                                                 
           }                                                                  
         clock_gettime(CLOCK_MONOTONIC, &end);                                
                                                                              
         timespec_sub(&result, &end, &start);                                 
         printf("%d:spending %d.%lds\n", loop, result.tv_sec, result.tv_nsec);
       }                                                                      
                                                                              
     close(fd);                                                               
     return 0;                                                                
   }                                                                          
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to