Is using Math.pow faster than multiplying myself?

Hi all,
Is it faster to use Math.pow to calculate a power than to, say, multiply it myself in a loop? How about if I'm just doing a square -- is it faster to use Math.pow(x,2) than x * x?
I noticed that the pow method in StrictMath has the keyword "native." Does this mean it's being done by the operating system? Does it mean it's being done directly in the hardware?
Thanks!
Tim

TimQuinn wrote:
This is in an inner-loop deep in a simulation, so I'd like it to be as fast as possible. From the above, I'm gathering that I should keep using pow for my ^8 calculation, but substitute a simple multiplication for my ^2 calculation.Not necessarily. Remember that N^8 = ((N^2)^2)^2. The Math.pow algorithm will very likely use this optimization, but you can too.
Related question: does it make any difference at all in these kinds of operations if I use floats or doubles? In terms of speed, I mean, not precision.Actual answer to all of your questions: try all of the possibilities in your simulation and see what actually happens.

Similar Messages

  • Decimal power without using Math.pow()

    how do you raise a decimal number (3.543) to a decimal power (4.235) without using Math.pow()?

    Use Math.log() and Math..exp().
    Math.exp(4.235*Math.log(3.543))

  • Can I safely use ac power rather than stay on battery all thentime?

    I use my ipad2 often. Can I safely use ac power vs battery without shortening bat. Life?

    Yes, but it is recommended to go through one complete discharge and charge cycle at least once a month.
    http://www.apple.com/batteries/
    A charge cycle means using all of the battery’s power, but that doesn’t necessarily mean a single charge. For instance, you could listen to your iPod for a few hours one day, using half its power, and then recharge it fully. If you did the same thing the next day, it would count as one charge cycle, not two, so you may take several days to complete a cycle.

  • Is using Media Encoder faster than Transcoding with Encore?

    I'm fairly new to the Adobe video side of things, I just switched over from Apple but I am really liking what I'm working with. I've been using the Adobe Dynamic link to edit and auther DVDs. It's nice to not have to overload my computer with exported movies, but it seems to take a very long time to transcode within Encore. What seems to be much quicker is exporting the file out of Premiere and then using Media Encoder to transcode it using the highest quality DVD preset (and switched it to CBR 9 Mbps since my video is only 10 minutes long). I guess I'm curious if this is the method that others use or if most people use Dynamic link to author DVDs.
    Thanks,
    Joel

    The problems some users experience tend to involve Bluray and dynamic link.
    For DVDs, I use dynamic link and like it. I do set the preference (available with CS5 and above when using Transcode Now ) for Encore to transcode movie assets using AME, and I transcode with transcode now prior to doing a build.
    I do not have a CUDA card, but my understanding is that AME is using 64 bit.

  • Math.pow versus multiply for squaring

    Does anyone know which is faster for squaring doubles? Using math.pow to raise the value to the power of two, or to simply multiply the value by itself.
    thanks.
    -Brian

    ^ As was my ill-advised original response to the @OP. :D

  • Ios 7 battery drain - using faster than charging now

    Anyone else have issues getting a full charge on iPhone 4S after updating to ios 7.0?
    It's draining noticable faster - battery drains faster than it charges now so that unless you turn off the screen you end up with less charge than when you docked it. Same goes for regular 30 pin cable to 1Amp wall charger without the dock.
    I left mine over night on the iPhone dock and it still only reached 92%
    Never had issues on ios 6.
    Even with the screen dimmed back to 50% (like I had it set for ios 6),
    Battery was at 45% before updated yesterday and even though it was docked and charging during update was at 36% after the update, and kept dropping the longer I had it connected.
    Does anyone know for sure if ios 7 is using the A5 cpu differently? maybe running it faster or using more power than on ios 6?
    Rebooted my iPhone 4S a few times after updating, nosame issue. Was able to use Safari but unable to download from itunes or app store. They asked or my password, but it said "could not connect to app store, please try again". perhaps due to so many users updating yesterday
    Then after opening a few apps (ebay, amazon) battery meter jumped to 100%
    I do have DND enabled for notice center. update retained that preference and my screen lock code.
    I noticed that even though screen lock timeout was set for 2 mins, it was prompting for code immediately. Had to change to 5 mins, since the 2 minute to lock option has been removed in ios 7.
    Thanks,
    JJ

    Anyone else have issues getting a full charge on iPhone 4S after updating to ios 7.0?
    It's draining noticable faster - battery drains faster than it charges now so that unless you turn off the screen you end up with less charge than when you docked it. Same goes for regular 30 pin cable to 1Amp wall charger without the dock.
    I left mine over night on the iPhone dock and it still only reached 92%
    Never had issues on ios 6.
    Even with the screen dimmed back to 50% (like I had it set for ios 6),
    Battery was at 45% before updated yesterday and even though it was docked and charging during update was at 36% after the update, and kept dropping the longer I had it connected.
    Does anyone know for sure if ios 7 is using the A5 cpu differently? maybe running it faster or using more power than on ios 6?
    Rebooted my iPhone 4S a few times after updating, nosame issue. Was able to use Safari but unable to download from itunes or app store. They asked or my password, but it said "could not connect to app store, please try again". perhaps due to so many users updating yesterday
    Then after opening a few apps (ebay, amazon) battery meter jumped to 100%
    I do have DND enabled for notice center. update retained that preference and my screen lock code.
    I noticed that even though screen lock timeout was set for 2 mins, it was prompting for code immediately. Had to change to 5 mins, since the 2 minute to lock option has been removed in ios 7.
    Thanks,
    JJ

  • New to apple and wondering if using keynote is easier than power point.

    Hello all,
    I have only been using os x for about 6 months, and I was wondering if using keynote is easier than power point? I am in school so I need to know if keynote will save in ppt format. The school that I go to only uses MS office 97 to 2004 format for all docs and power points. Is using keynote that much different?

    i find keynote MUCH easier in almost all areas. it did take me a little learning in the beginning. the main thing to know is that apple uses a floating pallet call "inspector" to control just about all the details of the presentation. they also have a "formatting bar" which is conceptually similar to the formatting bars microsoft uses in the previous versions of office (font size, etc...).
    the basic entry for slides is the same, where one just types into the fields on the slides. what i find much better is the control i have in the "inspector" to fine tune anything. i've gotten completely dependent on keynotes "staging" which is how one makes the slides animate. if i have a series of bullets and a diagram, i use the staging to get the diagram to be revealed in stages and to get the bullets appear one at a time in sync with the diagram i'm explaining. nothing is more boring for an audience to have someone just stand up, thru up a slide with 100 words and read the text bullets.
    i find keynote to be much easier to develop diagrams or to copy and paste in a PDF picture. then add the staging effects i need to develop the story to explain the diagram or picture. it does take a little learning how to do it the first couple times. but the interface is consistent and it's not hard to learn it.
    the only aspect i find a little easier in powerpoint is the indenting style, which is controlled in one of the editing buttons in office 11 and before. keynote controls the indenting from the "inspector" instead of having a little button in the formatting bar. but in every other way, i find keynote to be MUCH easier to use. and it has other features that powerpoint doesn't have. plus iwork is very inexpensive compared to microsoft office. finally, if you are near an apple store, they have free seminars on iWork fairly often. the 1st time i used keynote, i went to the apple store workshop and got a few answers. just see how easy it is to get person to person help for microsoft office...
    the only other game in town are the various releases of the open source programs, "open office" and "neo office". they are free, also read and write ppt files, but are a little harder to use than keynote and don't have as many features.
    anyway, that's my experience.
    good luck!

  • Are the brushes in Photoshop CC faster than CS6 - still need to use CS5 for large files

    Hey,
    Are the brushes in Photoshop CC any faster than Photoshop CS6.
    Here's my standard large file, which makes the CS6 brushes crawl:
    iPad 3 size - 2048 x 1536
    About 20-100 layers
    A combination of vector and bitmap layers
    Many of the layers use layer styles
    On a file like this there is a hesitation to every brush stroke in CS6. Even a basic round brush has the same hesitation, it doesn't have to be a brush as elaborate as a mixer brush.
    This hesitation happens on both the mac and pc, on systems with 16 gb of ram. Many of my coworkers have the same issue.
    So, for a complicated file, such as a map with many parts, I ask my coworkers to please work in CS5. If they work in CS6 I ask them to not use any CS6 only features, such as group layer styles. The only reason why one of them might want to use CS6 is because they're working on only a small portion of the map, such as a building. The rest of the layers are flattened in their file.
    Just wondering if there has ever been a resolution to this problem...or this is just the way it is.
    Thanks for your help!

    BOILERPLATE TEXT:
    Note that this is boilerplate text.
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CS6", but something like CS6v.13.0.6) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    etc.,
    someone may be able to help you (not necessarily this poster, who is not a Windows user).
    a screen shot of your settings or of the image could be very helpful too.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • Is this logging code faster than using a standard logging API like log4J

    is this logging code faster than using a standard logging API like log4J or the logging API in java 1.4
    As you can see my needs are extremely simple. write some stuff to text file and write some stuff to dos window.
    I am thinking about using this with a multi threaded app. So all the threads ~ 200 will be using this simultaneously.
    * Tracer.class logs items according to the following criteria:
    * 2 = goes to text file Crawler_log.txt
    * 1 = goes to console window because it is higher priority.
    * @author Stephen
    * @version 1.0
    * @since June 2002
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.text.*;
    class Tracer{
    public static void log(int traceLevel, String message, Object value)
    if(traceLevel == 1){
    System.out.println(getLogFileDate(new Date()) +" >" + message+ " value = " + value.toString()););
    }else{
    pout.write(getLogFileDate(new Date()) +" >" + message + " value = " + value.toString());
    pout.flush();
    public static void log(int traceLevel, String message )
    if(traceLevel == 1){System.out.println(message);
    }else{
    pout.write(message ) ;
    pout.flush();
    //public static accessor method
    public static Tracer getTracerInstance()
    return tracerInstance;
    private static String getLogFileDate(Date d )
    String s = df.format(d);
    String s1= s.replace(',','-');
    String s2= s1.replace(' ','-');
    String s3= s2.replace(':','.');
    System.out.println("getLogFileDate() = " + s3 ) ;
    return s3;
    //private instance
    private Tracer(){
    System.out.println("Tracer constructor works");
    df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    date = new java.util.Date();
    try{
    pout = new PrintWriter(new BufferedWriter(new FileWriter("Crawler_log"+getLogFileDate(new Date())+".txt", true)));
    pout.write("**************** New Log File Created "+ getLogFileDate(new Date()) +"****************");
    pout.flush();
    }catch (IOException e){
    System.out.println("**********THERE WAS A CRITICAL ERROR GETTING TRACER SINGLETON INITIALIZED. APPLICATION WILL STOP EXECUTION. ******* ");
    public static void main(String[] argz){
    System.out.println("main method starts ");
    Tracer tt = Tracer.getTracerInstance();
    System.out.println("main method successfully gets Tracer instance tt. "+ tt.toString());
    //the next method is where it fails - on pout.write() of log method. Why ?
    tt.log(1, "HIGH PRIORITY");
    System.out.println("main method ends ");
    //private static reference
    private static Tracer tracerInstance = new Tracer();
    private static Date date = null;
    private static PrintWriter pout = null;
    public static DateFormat df = null;
    }

    In general I'd guess that a small, custom thing will be faster than a large, generic thing with a lot of options. That is, unless the writer of the small program have done something stupid, og the writer of the large program have done something very smart.
    One problem with java in this respect is that it is next to impossible to judge exactly how much machine-level processing a single java statement takes. Things like JIT compilers makes it even harder.
    In the end, there is really only one way to find out: Test it.

  • Video faster than audio when use Adobe Media Encoder to convert f4v to mp4

    I am using Adobe Captivate 5 on a  mac record a demonstration, and I have published my project to .f4v. Now I am using Adobe Media encoder to convert the .f4v file to .mp4 (to play on an ipod). The output LOOKS good, but the video is running much faster than the audio. To be clear, the audio is running at the correct pace, but the video is going by much too quickly.

    From Captivate, I tried changing the fps to a variety of speeds (12, 20, 30, 40, 60) when publishing to f4v. Then in Adobe Media Encoder, when I converted to mp4, I tried keeping the fps the same as the source f4v, reducing it, or increasing it.  After all these experiments, I found that changing the fps in Adobe Media Encoder had no effect at all. Only changing the fps in the source f4v had an effect.  Reducing it to 12 made the probelm worse (the video went by even faster), and increasing it as high as 60 made a SLIGHT improvement, but not enough to get things in sync. Changing the key frame distance in AME had no effect.

  • Myth or Truth, iMac uses less power in Standby than when off

    I'm sure I read this somewhere on the internet.
    I'm not sure what model it was for, but I heard that the imac uses less power when in sleep than being shutdown (when still plugged into the wall)
    Can anyone confirm or denigh this?
    Ifs it true any web links to this?

    If it's powered off, it's using no power at all.
    I suspect this is about the power cost of waking from standby versus pwoering up from off, and whether it makes more sense to leave your Mac in standby when out of use or whether to swticth off completely.
    It depends on your usage pattern. If you leave the Mac unused for very long periods of time, it makes sense to power off, because standby uses a little power constantly. If you leave it unused for shortter periods, you probably use less power in standby.
    Unfortunately, I don't have a magic number for the time period
    As a rule of thumb, I'd say if it's unused for less than a day or so, standby makes more sense. There's a discussion at the link below which also fails to give a definitive answer but has some interetsing comments.
    http://apple.stackexchange.com/questions/7588/for-least-power-usage-should-i-tur n-off-or-put-my-mac-to-sleep

  • HT4060 I'm having some problems with my ipad and charging it. I am having to leave it in charge for a lot longer, but when I take it out and want to use it the battery is still not completely full and goes down a lot faster than usual

    I'm having some problems with my ipad and charging it. I am having to leave it in charge for a lot longer, but when I take it out and want to use it the battery is still not completely full and goes down a lot faster than usual. The other day, I had charged  my iPad overnight so that I could take it to university with me for the day, and when I had switched it on the next day the battery was on 5% and I had not used it since charge.

    Your battery may be dying. THey are only good for so many charges/discharges. If you have an apple store near by make an appointment and have them check itout

  • Why is JVM faster than CLR?

    hi
    i wrote a N-body algorithm in both Java and C# (shown below). i executed it using .NET CLR and JDK1.4.1. in JDK it is twice as fast as .NET (on win2000). now i am trying to find out why is it so??
    the interesting thing is that i ran some other algorithms like FFT and graph alogrithms, and they are faster in .NET. so i want to find is there some operation in the below algorithm that is making it run faster in JDK.
    in general, what can the possible reasons be for JVM to run faster than CLR?
    thanks
    double G = 6.6726E-11;
    double difference = 0.0;
    for(int i=0; i<numBodies; i++)
         accelarations[i] = 0.0;
         for(int j=0; j<numBodies; j++)
              if(i != j)
              difference = radii[i] - radii[j];
              if(difference != 0)
              accelarations[i] += masses/(Math.pow(difference, 2));
         accelarations[i] *= G;

    Interesting N-Body problem that treats accelerations as scalars.
    Anyway, if there is no optimisation for small integer powers in the Math.pow() method, then I'd expect almost all the time is used there or in its equivalent in .NET. Hardly a meaningful test of relative performance.
    Try using (difference * difference) instead.
    Sylvia.

  • Is the Core i7 processor comparable, much slower, or faster than the 2.8 Ghz core 2 duo from 2009?

    I am looking to get a new MacBook Air, but when looking at the prices I am seeing the MacBook Pro 13" for the same price and a lot more guts (RAM and Processor).  I am ok with spending the amount of money on the air if it means I get a computer that is like my iPad, which i love (flash based, snappy), but don't want it to be super slow.
    I am coming off of a 17" 2.8Ghz MacBook Pro from 2009.  I was happy with the speed and power of that machine.  The most taxing thing I did was make a complilation of family movies in iMovie and burned them with iDVD once in the 2 years of ownership. 
    I mostly browse the internet and compose written documents, and keynote presentations.
    I know my questions may seem stupid, but I don't know how significant the changes between i7 and Core 2 Duo are, so I ask the question:
    I am wondering if the processing power in the core i7 will be somewhat comparable, much slower, or faster than the 2.8 Ghz Core 2 Duo I had in my 2009 computer?
    Thanks for any help!!

    Hi brosephb,
    Like you I went through a similar comparison process. I bought the MacBook air 13" and up specced the processor and memory. I don't do anything taxing enough or frequently enough to NEED the extra power of the MacBook pro.
    I am overjoyed at my air. It's gorgeous, the way it wakes instantly, it's speed and it's portableness is so endearing that I just don't use my iPad anymore. I read numerous reviews on it and the overwhelming opinion was it's addictive ease of use because of it's slim, light and rapid waking. At work I can hold the air with one hand, open it rapidly at will. It's just great but it's made my iPad redundant (for me anyway).
    I see the new airs are even faster and I'm tempted to consider selling my 6 month old air and getting the new one, but, it runs a dream so I am happy to just be envious of the new one.
    In short, unless you need the power (for your work) go for the air. I'm looking at a new iMac to use as a home work station. For the price of a new air I can get an iMac that will swallow any task for a good few years to come. And my air will suffice as my mobile companion. However, that's just me spoiling myself as, at the moment, I have no teal need for another mac. I may get the cinema display for any long winded tasks, as the screen size will help with multiple tasking.
    A bit of a ramble, hope this is useful.

  • Can I charge my new ipod using firewire power adapter?

    Just got my new 30GB ipod and realised that it doesn't come with power adapter to plug in directly in power outlet.
    Can I use the firewire power adapter which I have leftover after my 3rd gen ipod died on me?
    Also can I use the firewire to connect it to my powerbook for charging and song transfer? I thought firewire is faster than usb2 then why new ipods don't come with firewire cable anymore?
    Many thanks.
    PowerBook G4   Mac OS X (10.4.5)  

    think if you do your research and read up you will see the USB2 is indeed faster than Firewire. I actually did a few test on a dual G5 using both the Firewire and USB2 and in all my test, USB2 was faster.
    If USB2 was faster for you, that's wonderful. I'm not about to start arguing with you over it.
    What I can tell you is that you're certainly in the minority if this was the case for you.
    USB2 has a theoretical maximum speed of 480Mbps. While this is certainly a higher number than Firewire 400's 400Mbps, Firewire will still vastly outperform USB2 in almost every case. It is near impossible to get anywhere close to 480Mbps with USB2. Even under ideal conditions, USB2 still has to contend with other processes on the machine, and other devices in the bus.
    This is the nature of USB's design.
    It is not uncommon for Firewire to reach near maximum speeds consistently. This has been proven time and time again.
    Like I mentioned already, if USB2 is faster for you... go ahead and use it. I'm not going to tell you otherwise.
    I'm quite sure I've done sufficient research on this, as well as many other people in this industry, and these forums. Perhaps it is you that might want to do a little more reading.

Maybe you are looking for