Beispiel #1
0
        public PerformanceResult RunTest(string testName, int testCount, Action <int> beforeTest, Action <int> test,
                                         Action <int> afterTest)
        {
            PerformanceTarget target = GetTarget(testName);
            Stopwatch         sw     = new Stopwatch();

            for (int i = 0; i < testCount; i++)
            {
                beforeTest?.Invoke(i);
                sw.Start();
                test(i);
                sw.Stop();
                afterTest?.Invoke(i);
            }

            decimal result = (decimal)sw.Elapsed.TotalMilliseconds;

            if (target == null)
            {
                target = new PerformanceTarget(testName, result, testCount);
                Targets.Add(target);
                WriteTarget(target);
            }

            return(new PerformanceResult(target, testCount, result));
        }
        /// <summary>
        /// Creates a performance target for the campaign group.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignGroupId">Campaign group ID.</param>
        /// <returns>The newly created performance target.</returns>
        private static CampaignGroupPerformanceTarget CreatePerformanceTarget(AdWordsUser user,
                                                                              long campaignGroupId)
        {
            using (CampaignGroupPerformanceTargetService campaignGroupPerformanceTargetService =
                       (CampaignGroupPerformanceTargetService)user.GetService(
                           AdWordsService.v201710.CampaignGroupPerformanceTargetService)) {
                // Create the performance target.
                CampaignGroupPerformanceTarget campaignGroupPerformanceTarget =
                    new CampaignGroupPerformanceTarget();
                campaignGroupPerformanceTarget.campaignGroupId = campaignGroupId;

                PerformanceTarget performanceTarget = new PerformanceTarget();
                // Keep the CPC for the campaigns < $3.
                performanceTarget.efficiencyTargetType  = EfficiencyTargetType.CPC_LESS_THAN_OR_EQUAL_TO;
                performanceTarget.efficiencyTargetValue = 3000000;

                // Keep the maximum spend under $50.
                performanceTarget.spendTargetType = SpendTargetType.MAXIMUM;
                Money maxSpend = new Money();
                maxSpend.microAmount          = 500000000;
                performanceTarget.spendTarget = maxSpend;

                // Aim for at least 3000 clicks.
                performanceTarget.volumeTargetValue = 3000;
                performanceTarget.volumeGoalType    = VolumeGoalType.MAXIMIZE_CLICKS;

                // Start the performance target today, and run it for the next 90 days.
                System.DateTime startDate = System.DateTime.Now;
                System.DateTime endDate   = startDate.AddDays(90);

                performanceTarget.startDate = startDate.ToString("yyyyMMdd");
                performanceTarget.endDate   = endDate.ToString("yyyyMMdd");

                campaignGroupPerformanceTarget.performanceTarget = performanceTarget;

                // Create the operation.
                CampaignGroupPerformanceTargetOperation operation =
                    new CampaignGroupPerformanceTargetOperation();
                operation.operand   = campaignGroupPerformanceTarget;
                operation.@operator = Operator.ADD;

                try {
                    CampaignGroupPerformanceTargetReturnValue retval =
                        campaignGroupPerformanceTargetService.mutate(
                            new CampaignGroupPerformanceTargetOperation[] { operation });

                    // Display the results.
                    CampaignGroupPerformanceTarget newCampaignPerfTarget = retval.value[0];

                    Console.WriteLine("Campaign performance target with id = '{0}' was added for " +
                                      "campaign group ID '{1}'.", newCampaignPerfTarget.id,
                                      newCampaignPerfTarget.campaignGroupId);
                    return(newCampaignPerfTarget);
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create campaign performance target.",
                                                          e);
                }
            }
        }
Beispiel #3
0
 public PerformanceResult(PerformanceTarget target, int n, decimal result)
 {
     LowerIsBetter = target.LowerIsBetter;
     TestName      = target.TestName;
     N             = n;
     Result        = result;
     Target        = target.Target;
     Variance      = target.Variance;
 }
Beispiel #4
0
        private void OnGUI()
        {
            windowScrollPosition = EditorGUILayout.BeginScrollView(windowScrollPosition);

            MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo();

            // Render Title
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Mixed Reality Toolkit Optimize Window", MixedRealityStylesUtility.BoldLargeTitleStyle);
                InspectorUIUtility.RenderDocumentationButton(OptimizeWindow_URL);
            }

            EditorGUILayout.LabelField("This tool automates the process of updating your project, currently open scene, and material assets to recommended settings for Mixed Reality", EditorStyles.wordWrappedLabel);
            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Active Build Target: ", EditorUserBuildSettings.activeBuildTarget.ToString());

            PerfTarget = (PerformanceTarget)EditorGUILayout.Popup("Performance Target", (int)this.PerfTarget, PerformanceTargetEnums);
            EditorGUILayout.HelpBox(PerformanceTargetDescriptions[(int)PerfTarget], MessageType.Info);
            EditorGUILayout.Space();

            if (!PlayerSettings.virtualRealitySupported)
            {
                EditorGUILayout.HelpBox("Virtual reality support is not enabled in player settings", MessageType.Error);
                if (GUILayout.Button("Enable Virtual Reality Support"))
                {
                    PlayerSettings.virtualRealitySupported = true;
                }
            }
            else
            {
                selectedToolbarIndex = GUILayout.Toolbar(selectedToolbarIndex, ToolbarTitles);
                if (selectedToolbarIndex == 0)
                {
                    RenderSettingOptimizations();
                }
                else if (selectedToolbarIndex == 1)
                {
                    RenderSceneOptimizations();
                }
                else
                {
                    RenderShaderOptimizations();
                }
            }

            EditorGUILayout.EndScrollView();
        }
Beispiel #5
0
        private void WriteTarget(PerformanceTarget target)
        {
            Stream s = null;

            try
            {
                s = File.Create(Path.Combine(TARGET_DIRECTORY, target.TestName + ".xml"));
                XmlSerializer xs = new XmlSerializer(typeof(PerformanceTarget));
                xs.Serialize(s, target);
                s.Close();
            }
            catch (Exception)
            {
                s?.Close();
            }
        }
        private void OnGUI()
        {
            windowScrollPosition = EditorGUILayout.BeginScrollView(windowScrollPosition);

            // Render MRTK Logo
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(EditorGUIUtility.isProSkin ? logoDarkTheme : logoLightTheme, GUILayout.MaxHeight(128f));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            // Render Title
            EditorGUILayout.LabelField("Mixed Reality Toolkit Optimize Window", BoldLargeTitle);
            EditorGUILayout.LabelField("This tool automates the process of updating your project, currently open scene, and material assets to recommended settings for Mixed Reality", EditorStyles.wordWrappedLabel);
            EditorGUILayout.Space();

            PerfTarget = (PerformanceTarget)EditorGUILayout.Popup("Performance Target", (int)this.PerfTarget, PerformanceTargetEnums);
            EditorGUILayout.HelpBox(PerformanceTargetDescriptions[(int)PerfTarget], MessageType.Info);
            EditorGUILayout.Space();

            if (!PlayerSettings.virtualRealitySupported)
            {
                EditorGUILayout.HelpBox("Current build target does not have virtual reality support enabled", MessageType.Warning);
            }

            selectedToolbarIndex = GUILayout.Toolbar(selectedToolbarIndex, ToolbarTitles);
            if (selectedToolbarIndex == 0)
            {
                RenderProjectOptimizations();
            }
            else if (selectedToolbarIndex == 1)
            {
                RenderSceneOptimizations();
            }
            else
            {
                RenderShaderOptimizations();
            }

            EditorGUILayout.EndScrollView();
        }