Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:02:35+00:00 2026-06-17T15:02:35+00:00

I was just curious If a function needs to return large number of variables

  • 0

I was just curious
If a function needs to return large number of variables does it necessarily take longer to execute? I have a function that calculates values and stores them in arrays. It calculates these values every time it’s called and the number of times it is called has not changed. However now that I have added some return values (each one is a large array with around 1500 double elements, the function returns 8~10 such arrays as opposed to just calculating them) the function seems to take longer to execute (checked using tic before the function call and toc after the function call. Does this cause the total execution time to be more?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:02:37+00:00Added an answer on June 17, 2026 at 3:02 pm

    In fact it does take longer if you let the function output more arguements. I guess it is related to storing the result.

    Here is my testfunction:

    function [q, w, e, r, t, y, u, i, o, p] = tests
    
    q = rand(100);
    w = rand(100);
    e = rand(100);
    r = rand(100);
    t = rand(100);
    y = rand(100);
    u = rand(100); 
    i = rand(100); 
    o = rand(100); 
    p = rand(100); 
    

    And these are the setups that I used to test the speed:

    clear
    tic
    for i = 1:100
       %q = tests; %Only one output argument
       [q w e r t y u i o p] = tests; %Several output arguments
    end
    toc
    

    The difference is not huge, but I ran it several times and it does appear to be significant here are the results:

    Only one output argument: 0.1354 average +- 0.0001
    Several output arguments: 0.1367 average +- 0.0001
    

    So it will take longer, but I doubt whether the difference is ever interesting enough to outweigh other considerations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a function that needs to return some integer value. but
Just curious. How does actually the function Sleep() work (declared in windows.h)? Maybe not
Just curious, I have this function: setInterval( function(){ sendAjax('search', eInput, function(responseText){ $(#txtResp).html(responseText); }) },
Just curious what is the best practice for solving the following issue. I have
I have a Factory class that creates a Widget object. The Factory object needs
I'm curious on how to implement such a function. For example, I have something
I am just curious. Let's say for example I need to output a number
I'm just curious, is it possible to dump all the variables and current state
Just curious, is there a format string I can use to output something like
Just curious if I'm creating a shared memory array on Windows platform like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.